Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
How to reproduce?
com.android.server.am.CachedAppOptimizerTest:. Process crashed while executing fullCompactionDeltaRssThrottleKb_listensToDeviceConfigChangesBadValues(com.android.server.am.CachedAppOptimizerTest): java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Set java.util.HashMap.keySet()' on a null object reference at android.provider.DeviceConfig$Properties.getKeyset(DeviceConfig.java:1517) at com.android.server.am.CachedAppOptimizer$1.onPropertiesChanged(CachedAppOptimizer.java:287) at com.android.modules.utils.testing.TestableDeviceConfig.lambda$invokeListeners$13(TestableDeviceConfig.java:181) at com.android.modules.utils.testing.TestableDeviceConfig$$ExternalSyntheticLambda12.run(Unknown Source:4) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:222) at android.os.Looper.loop(Looper.java:314) at android.app.ActivityThread.main(ActivityThread.java:8561) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:959) INSTRUMENTATION_RESULT: shortMsg=Process crashed. INSTRUMENTATION_CODE: 0
How to Fix
From analysis, I think this is a corner case of TestableDeviceConfig. We should create a spy of the real Properties object instead of mocking it. As the testing thread is always not the same thread as invoking listeners thread, if we tear down tesing and finish mocking at a very delicate time, the invoking listener thread could cause NPE when calling Properties.getKeyset.