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

NullPointerException when showing Android Modal #10795

Closed
idris opened this issue Nov 7, 2016 · 18 comments
Closed

NullPointerException when showing Android Modal #10795

idris opened this issue Nov 7, 2016 · 18 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@idris
Copy link

idris commented Nov 7, 2016

Description

We are getting a NullPointerException sometimes upon trying to show a modal (see "Reproduction" section for details).

Stack Trace:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.setStyleWidth(float)' on a null object reference
	at com.facebook.react.uimanager.UIImplementation.updateNodeSize(UIImplementation.java:151)
	at com.facebook.react.uimanager.UIManagerModule.updateNodeSize(UIManagerModule.java:213)
	at com.facebook.react.views.modal.ReactModalHostView$DialogRootViewGroup$1.run(ReactModalHostView.java:301)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
	at android.os.Looper.loop(Looper.java:148)
	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
	at java.lang.Thread.run(Thread.java:818)

It sounds like this commit may be related, and may have fixed a similar issue: 922cd6d
From that commit message:

In some cases, the size of the content view changes before we add views to the
Modal. That means that the size of that view will not be set through the
onSizeChanged method. This can result in some apps apparently freezing,
since the dialog is created, but there are no actual views in it.

The part about "dialog is created, but there are no actual views in it" makes me feel it's related, because the NullPointerException happens here: https://github.com/facebook/react-native/blob/v0.36.0/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java#L301-L302
So apparently getChildAt(0).getId() returns an ID that is unavailable by the time setStyleWidth is called.

Reproduction

Unfortunately, it's a tough case to reproduce. Even in our app it only happens about half the time. We have one modal show first, and when the user clicks "OK" on that one, we show another "saving" modal, then when saving is complete we remove the modal. It seems in between the user clicking "OK" and the "saving" modal displaying, we get a crash (about half the time).

Additional Information

  • React Native version: v0.36.0
  • Platform: Android (tested on Nexus 5)
  • Operating System: Android (Tried genymotion, but can only reproduce on a real device)
@charpeni
Copy link
Contributor

charpeni commented Nov 9, 2016

@facebook-github-bot label Android

@facebook-github-bot facebook-github-bot added Android Ran Commands One of our bots successfully processed a command. labels Nov 9, 2016
@akzhou
Copy link

akzhou commented Nov 9, 2016

I have the same question on React Native version: v0.36.1

@kruczy
Copy link

kruczy commented Nov 23, 2016

Hi,
I have a similar issue that happens only when closing a modal (but not always), the error is in a different place in the code but it seems it is related: https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIImplementation.java#L151

hope this helps with solving the problem

@idris
Copy link
Author

idris commented Nov 29, 2016

Looks like @Proberts has a way to reproduce this: #10845 (comment)

@fermuch
Copy link

fermuch commented Dec 5, 2016

Same issue in RN 0.39.0. It happens randomly, but seems to be triggered by onLayout on the root component.

@grahamtallen
Copy link

+1

@mwbres
Copy link

mwbres commented Feb 2, 2017

I only experience this crash on QA or prod builds for some reason. But yeah, this still needs a solution(v0.39).

@mwbres
Copy link

mwbres commented Feb 11, 2017

My company needed a fix for this, as this crash was happening in production and it was vital we fixed it, but we were unable to come up with a good method of testing and fixing this issue. We managed to "fix" the issue by ripping out the Modal component from our code. In our case, Modal was used to show a loading indicator.

We definitely need a true fix for this issue though.

@JakeRawr
Copy link
Contributor

+1, This happens for me even if visible = { false }

@butchmarshall
Copy link

butchmarshall commented Apr 3, 2017

I get this crash randomly while using react-native-loading-spinner-overlay

@gsaandy
Copy link

gsaandy commented Apr 6, 2017

any updates on this?

@fermuch
Copy link

fermuch commented Apr 6, 2017

@gsaandy after using a custom version compiled from master, the problem is gone for me.
I'm using react-native-router-flux for navigation.

@kelvinaliyanto
Copy link

Any workaround for this now?

@jlo1
Copy link

jlo1 commented May 10, 2017

Seems fixed in latest 0.44.0 release (5873a22)

@charpeni
Copy link
Contributor

Then let's close this, if it happens again please open a new issue.

@charpeni
Copy link
Contributor

@facebook-github-bot close

@facebook-github-bot
Copy link
Contributor

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Jul 12, 2017
@weimengxi
Copy link

@JakeRawr I've met this problem, too. visible = { false } leads to crash in ios .

@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests