Repository: facebook/stetho

Issue #381: NullPointerException
Created: 2016-05-04T04:45:18Z
I'm can't reproduce it every time  (version 1.3.1)
Process: com.adoriasoft.quietping, PID: 9303
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null
at com.facebook.stetho.inspector.elements.Document$4.store(Document.java:388)
at com.facebook.stetho.inspector.elements.ShadowDocument$Update.getChangedElements(ShadowDocument.java:297)
at com.facebook.stetho.inspector.elements.Document.applyDocumentUpdate(Document.java:372)
at com.facebook.stetho.inspector.elements.Document.updateTree(Document.java:327)
at com.facebook.stetho.inspector.elements.Document.access$1200(Document.java:30)
at com.facebook.stetho.inspector.elements.Document$ProviderListener.onPossiblyChanged(Document.java:682)
at com.facebook.stetho.inspector.elements.android.AndroidDocumentProvider$1.run(AndroidDocumentProvider.java:67)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

Duplicate issue #375: Irreproducible NPE during onPossiblyChanged
Created: 2016-04-18T10:25:20Z
I got a crash which I couldn't reproduce, sorry. I still thought it might be helpful to report it.
I did the following in my app (as far as I remember):

[laptop/phone] run the app from IDEA (main activity)
[phone] open an activity linked from main
[laptop] inspect its UI in Chrome
[laptop] back to IDEA (Developer Tools left open)
[phone] back button -> main activity
[phone] open navigation drawer -> crash:

java.lang.NullPointerException
    at com.facebook.stetho.inspector.elements.Document$4.store(Document.java:388)
    at com.facebook.stetho.inspector.elements.ShadowDocument$Update.getChangedElements(ShadowDocument.java:297)
    at com.facebook.stetho.inspector.elements.Document.applyDocumentUpdate(Document.java:372)
    at com.facebook.stetho.inspector.elements.Document.updateTree(Document.java:327)
    at com.facebook.stetho.inspector.elements.Document.access$1200(Document.java:30)
    at com.facebook.stetho.inspector.elements.Document$ProviderListener.onPossiblyChanged(Document.java:682)
    at com.facebook.stetho.inspector.elements.android.AndroidDocumentProvider$1.run(AndroidDocumentProvider.java:67)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5356)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at dalvik.system.NativeStart.main(Native Method)

Looking at the code:
/*387*/ if (newElementInfo.parentElement != oldElementInfo.parentElement) {
/*388*/     int parentNodeId = mObjectIdMapper.getIdForObject(oldElementInfo.parentElement);
/*389*/     int nodeId = mObjectIdMapper.getIdForObject(element);
/*390*/     mUpdateListeners.onChildNodeRemoved(parentNodeId, nodeId);
/*391*/ }
oldElementInfo cannot be null, because then the if would've thrown.
mObjectIdMapper is initialized in the constructor and is final, so cannot be null
Short WTF, then realized:
public @Nullable Integer getIdForObject(Object object);
So that leaves the hidden unboxing as the culprit: it is declared as nullable, but not checked for null. I guess it was assumed that it always exists?

Closing comment (2016-11-21T21:47:06Z): Duplicate of #381