question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android crash / NullPointerException

See original GitHub issue

For some reason, in android release builds on my app (or debug builds if I configure minifyEnabled true for debug buildType) this crashes on this line (I carefully deobfuscated the stack trace, and it’s definitely crashing here - no idea why minify triggers it when it’s not the classic ClassNotFoundException or NoClassDef etc that proguard would normally throw)

09-30 22:08:02.832  8709  8709 E unknown:ReactNative: Exception in native call
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.HashMap.get(java.lang.Object)' on a null object reference
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at h5.f.r(:218)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.uimanager.z0$m.a(:217)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.uimanager.z0$a.run(:915)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.uimanager.z0.U(:1026)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.uimanager.z0.s(:47)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.uimanager.z0$j.c(:1086)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.uimanager.f.a(:29)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.modules.core.g$d.a(:175)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.facebook.react.modules.core.a$a$a.doFrame(:85)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:970)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.view.Choreographer.doCallbacks(Choreographer.java:796)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.view.Choreographer.doFrame(Choreographer.java:727)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.os.Handler.handleCallback(Handler.java:938)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.os.Looper.loop(Looper.java:223)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at android.app.ActivityThread.main(ActivityThread.java:7656)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at java.lang.reflect.Method.invoke(Native Method)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
09-30 22:08:02.832  8709  8709 E unknown:ReactNative: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

And the relevant portion of android/app/build/outputs/mapping/debug/mapping.txt showing what h5.f.r is:


com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager -> h5.f:
    java.util.HashMap cleanerCallback -> n
    java.util.HashMap toBeRemoved -> m
    com.facebook.react.uimanager.layoutanimation.LayoutAnimationController mReaLayoutAnimator -> o
    java.util.HashMap mPendingDeletionsForTag -> p
    134:163:void <init>(com.facebook.react.uimanager.ViewManagerRegistry,com.facebook.react.bridge.ReactApplicationContext) -> <init>
    169:178:void updateLayout(int,int,int,int,int,int) -> C
    234:235:void publicDropView(android.view.View) -> G
    238:250:void dropView(android.view.View) -> n
    181:231:void manageChildren(int,int[],com.facebook.react.uimanager.ViewAtIndex[],int[]) -> r

So it’s in ReanimatedNativeHierarchyManager::manageChildren on line 218 - right where mPendingDeletionsForTag is dereferenced for a .get with no null check.

I believe that since mPendingDeletionsForTag is initialized to null, and only set to a valid HashMap in one of the constructors but not the other, I must be using the other constructor in my app.

Then when this line is hit, I get a null pointer exception.

I think this whole chunk could be wrapped in an if (mPendingDeletionsForTag != null) { /* ... */ }

_Originally posted by @mikehardy in https://github.com/software-mansion/react-native-reanimated/pull/2437#r719911428_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
mikehardycommented, Oct 6, 2021

It’s not actually a zip, sorry. It is literally just the .aar file with .zip added to it because GitHub will simply not allow you to attach an .aar (which is…technically a zip 😆 ) but it will allow a .zip. I’ll amend my instructions. You can try unzip -l react-native-reaniminated-66-hermes.aar.zip on command line (-l is just “list”, it’s safe, or should be) to verify if you like

2reactions
mikehardycommented, Oct 8, 2021

With sincere apologies I realize the aar I packed up and attached above does not contain the actual class that I fixed in the related PR. Why is that? Because in order to really test the fix I removed those exact classes from the aar and worked on the java file in my own app’s source tree. I got it working then of course forgot to put them back in the AAR I put here. So if anyone tried to use it before, you would have crashed on startup with a NoClassDefFoundError on ReanimatedNativeHierarchyManager.

I’ve put the classes in their rightful home in the AAR here and I’m re-attaching it. I only noticed myself when I went to take my own fix and put it in another app and couldn’t realize why it was crashing !?!. Apologies

react-native-reanimated-66-hermes.aar.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I fix android app crashing after a java.lang ...
I'm facing a java.lang.NullPointerException: Attempt to read from field 'android.widget.ImageView ...
Read more >
Major Android crash involving NullPointerException surfacing ...
Now I thinking they are rolling out a new version of Play Services that is causing app to crash. I haven't verified it...
Read more >
Crash in java.lang.NullPointerException: at android.view.View ...
Looks like Google Assistant has a newish setting where it retrieves info about the running app. It does this with the autofill API,...
Read more >
Detect and diagnose crashes - Android Developers
Null pointer exceptions (identified by the runtime error type NullPointerException ) occur when you're trying to access an object that is null, ...
Read more >
Bug: Application crashes due to NullpointerException while ...
NullPointerException 03-28 10:59:48.867: E/AndroidRuntime(19551): at com.google.android.apps.gmm.directions.g.c.<init>(PG:81)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found