Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random FileNotFoundException when mocking Android class #185

Open
lsuski opened this issue Oct 17, 2022 · 5 comments
Open

Random FileNotFoundException when mocking Android class #185

lsuski opened this issue Oct 17, 2022 · 5 comments

Comments

@lsuski
Copy link

lsuski commented Oct 17, 2022

Hi I've encountered this few times on CI but I couldn't reproduce this. When I try to mock NotificationManager class I recevice such error (on different devices):


  | Caused by:  java.io.FileNotFoundException:  /data/user/0/com.example.app/app_dxmaker_cache/Generated_1912252465.jar:  open failed: EACCES (Permission denied)
-- | --
2022-10-17T15:41:27.230Z | error | TestRunner | at libcore.io.IoBridge.open(IoBridge.java:575)
2022-10-17T15:41:27.230Z | error | TestRunner | at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
2022-10-17T15:41:27.230Z | error | TestRunner | at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
2022-10-17T15:41:27.230Z | error | TestRunner | at com.android.dx.DexMaker.generateAndLoad(DexMaker.java:537)
2022-10-17T15:41:27.230Z | error | TestRunner | at com.android.dx.stock.ProxyBuilder.buildProxyClass(ProxyBuilder.java:337)
2022-10-17T15:41:27.230Z | error | TestRunner | at com.android.dx.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:121)
2022-10-17T15:41:27.230Z | error | TestRunner | at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
@lsuski
Copy link
Author

lsuski commented Oct 17, 2022

I've managed to reproduce this on Android 12 but not every time:
Is it some bug on Android itself or
some race condition.
/data/user/0/com.example.app/app_dxmaker_cache seems to be app private folder which should be accessible without any permission and usually it is.

To workaround this I invoke Mockit.mock again in case of error and then it works

@cckroets
Copy link
Contributor

FYI @topjohnwu, this sounds like it could be related to your recent permission change in #181

@lsuski can you confirm if this behavior happens in the previous release (2.28.1) as well?

@lsuski
Copy link
Author

lsuski commented Oct 20, 2022

I'll try but as this is very rare I can't promise anything

@cckroets
Copy link
Contributor

@lsuski just checking in, any luck on reproducing this in 2.28.1?

@lsuski
Copy link
Author

lsuski commented Nov 22, 2022

No, I hadn't time for this yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants