linkedin / dexmaker

A utility for doing compile or runtime code generation targeting Android's Dalvik VM
Apache License 2.0
1.88k stars 249 forks source link

Random FileNotFoundException when mocking Android class #185

Open lsuski opened 2 years ago

lsuski commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

cckroets commented 1 year ago

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

lsuski commented 1 year ago

No, I hadn't time for this yet