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

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.uimanager.ReactShadowNode.setStyleWidth(float)' on a null object reference #10845

Closed
akzhou opened this issue Nov 10, 2016 · 84 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@akzhou
Copy link

akzhou commented Nov 10, 2016

Android tablet,when I assembleRelease the apk,modal view crash. debug not found this question.

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:302) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:194) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196) at java.lang.Thread.run(Thread.java:818)

Additional Information

  • React Native version: 0.36.1,0.37
  • Platform: android
  • Operating System: mac os
@ettysekhon
Copy link

ettysekhon commented Nov 11, 2016

I have found the same issue on release APK alse see #10795

@ettysekhon
Copy link

@akzhou I solved this by using the InteractionManager runAfterInteractions in a ComponentDidMount, see below for further details:

https://github.com/brentvatne/run-after-interactions-exp/blob/master/index.js

1 similar comment
@ettysekhon
Copy link

@akzhou I solved this by using the InteractionManager runAfterInteractions in a ComponentDidMount, see below for further details:

https://github.com/brentvatne/run-after-interactions-exp/blob/master/index.js

@akzhou
Copy link
Author

akzhou commented Nov 16, 2016

@ettysekhon it seem that you use renderPlaceholder replace modal view.at last,I fix it by compile the react-native source code with modify ReactModalHostView.java onSizeChanged method
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); return }
i don't know how the code work,at least no crash

@xujinyang
Copy link
Contributor

@akzhou can you push an PR to facebook?

@nadeermalangadan
Copy link

+1

1 similar comment
@bawn
Copy link

bawn commented Nov 25, 2016

+1

@Proberts
Copy link

Proberts commented Nov 29, 2016

This fix looks like it removes some important functionality.

FWIW I have this reproducible using redux and saga. I have a bool state variable mapped to a Modal component's 'visible" property. I change the state from false to true at the start of the saga. If I change the state back to false in the same saga I get this error consistently.

It seems like a safer band-aid would be to put a null test at line 151 (RN 0.37) in UIImplementation.java:

public void updateNodeSize(
      int nodeViewTag,
      int newWidth,
      int newHeight) {
    ReactShadowNode cssNode = mShadowNodeRegistry.getNode(nodeViewTag);
      if( cssNode != null ) {  // <-- right here
        cssNode.setStyleWidth(newWidth);
        cssNode.setStyleHeight(newHeight);
      }

    // If we're in the middle of a batch, the change will automatically be dispatched at the end of
    // the batch. As all batches are executed as a single runnable on the event queue this should
    // always be empty, but that calling architecture is an implementation detail.
    if (mOperationsQueue.isEmpty()) {
      dispatchViewUpdates(-1); // -1 = no associated batch id
    }
  }

@idris
Copy link

idris commented Nov 29, 2016

@Proberts can you create an app that reproduces this issue on https://rnplay.org and then attach it to #10795?

@Proberts
Copy link

@idris Trying but it looks like I can't import redux-saga. Not sure how to implement it without as I'm new to RN. I can try to make a minimal app that shows the problem and stick it on github. Would that help?

@idris
Copy link

idris commented Dec 1, 2016

@Proberts yeah that would probably be useful for react-native devs to have a way to reproduce it.

@jjdp
Copy link

jjdp commented Dec 8, 2016

+1

@Proberts
Copy link

Proberts commented Dec 8, 2016

FWIW I can't get it to reproduce in a minimal setup with the way I thought it was getting triggered in my code. I had it go away for a while after I moved some code being called from an onPress event handler into a saga. But it came back after I added to async calls to the saga - so at least I have a place to start looking.

@jideobs
Copy link

jideobs commented Dec 8, 2016

This problem is fresh. +1

@astapinski
Copy link

astapinski commented Dec 9, 2016

We're also encountering this crash on Google Android emulators API 23, RN 0.35 with automated runs via Calabash. We haven't seen it (yet thankfully?) on physical devices, but it's pretty annoying to have our automation fail so randomly. It also happens around the time of a modal display.

@madox2
Copy link

madox2 commented Dec 16, 2016

I am having the same issue. I have modal (fullscreen) and android keyboard on. It happens when I close it with enter key (onSubmitEditing). I've tried to close modal in InteractionManager.runAfterInteractions callback, but it didn't help.
However It seems to be working when I postpone it with setTimeout(..., 300)

@WPCWEG
Copy link

WPCWEG commented Dec 22, 2016

I have the same question on React Native
Version: 0.30.0
Platform: Android (Coolpad A8-930)

@miller
Copy link

miller commented Dec 27, 2016

+1

@yinghang
Copy link

Any updates?

1 similar comment
@rohitgoyal
Copy link

Any updates?

@rusel1989
Copy link

Yeah this bug is pretty nasty, i've got 2 bad reviews in play store because of it ...
I've used this fix

const CustomModal = ({ visible = false, children }) => {
  if (!visible) {
    return <View/>
  }
  return (
    <Modal
      style={styles.modalWrapper}
      animationType='slide'
      onRequestClose={() => {}}
      visible={true}
      transparent >
      {children}
    </Modal>
  )
}

Nothing fancy, but works okay

@raymond-cat
Copy link

I have the same question on React Native
Version: 0.39.0
Platform: Android

@SeanYe
Copy link

SeanYe commented Jan 13, 2017

+1

@Proberts
Copy link

I haven't seen this problem since I upgraded to 0.39.2 It might have been fixed by this commit

@K-Leon
Copy link
Contributor

K-Leon commented Jan 17, 2017

I've just seen it with 0.41-rc

@alex44jzy
Copy link

+1 the same problem in RN 0.39 Android 4.4.4. Also cause with the Modal. I am a little upset.
error-151

@RobTS
Copy link

RobTS commented Jan 18, 2017

Experiencing this randomly on startup as well. 0.4.0

@PierrePIRONIN
Copy link

PierrePIRONIN commented Jan 18, 2017

+1 with version 0.40

@astreet
Copy link
Contributor

astreet commented Mar 20, 2017

@grabbou This should be pretty safe to merge, what release can we get this into do you think?

@grabbou
Copy link
Contributor

grabbou commented Mar 20, 2017

Yeah, I'll include it in next RC tomorrow.

gregberns added a commit to gregberns/react-native that referenced this issue Mar 23, 2017
Patch

Error:
ReactShadowNode.setStyleWidth(float)' on a null object reference

facebook#10845
facebook/react-native@5873a22
@aamir-munir
Copy link

I am using RN 0.42.3, but I am still getting this error randomly on application start.
android-error

@cemo
Copy link

cemo commented Mar 25, 2017

@itcurves give a try with v0.43.0-rc.4. I think that this release contains necessary patch as @grabbou stated.

@TaranjeetSinghWri
Copy link

I added a delay of 1 second before showing the infected view page, which solved the issue temporarily

@TaranjeetSinghWri
Copy link

I think it is related to react-native-router-flux

@dcp12345678
Copy link

@cemo

I have not been able to run this release. I followed the documentation located here to upgrade to this release version you mentioned in your post, but when I try to do 'react-native run-android', this is what I get (see below). Is there any documentation for how to install one of these release versions?

  • What went wrong:
    A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
Could not resolve com.facebook.fresco:fresco:1.0.1.
Required by:
OrderEntry:app:unspecified > com.facebook.react:react-native:0.43.0-rc.
4
> Could not resolve com.facebook.fresco:fresco:1.0.1.
> Could not get resource 'https://jcenter.bintray.com/com/facebook/fres
co/fresco/1.0.1/fresco-1.0.1.pom'.
> Could not GET 'https://jcenter.bintray.com/com/facebook/fresco/fre
sco/1.0.1/fresco-1.0.1.pom'.
> jcenter.bintray.com
Could not resolve com.facebook.fresco:imagepipeline-okhttp3:1.0.1.
Required by:
OrderEntry:app:unspecified > com.facebook.react:react-native:0.43.0-rc.
4
> Could not resolve com.facebook.fresco:imagepipeline-okhttp3:1.0.1.
> Could not get resource 'https://jcenter.bintray.com/com/facebook/fres
co/imagepipeline-okhttp3/1.0.1/imagepipeline-okhttp3-1.0.1.pom'.
> Could not GET 'https://jcenter.bintray.com/com/facebook/fresco/ima
gepipeline-okhttp3/1.0.1/imagepipeline-okhttp3-1.0.1.pom'.
> jcenter.bintray.com

@liubobuzhidao
Copy link

@itcurves Do you have resolved this problem?

@kelvinaliyanto
Copy link

Is this issue already fixed in the latest release? Because I just checked my crashlytics and this issue seems to appear quite often.

@tianxind
Copy link

So this commit is not in RN 0.43?

grabbou pushed a commit that referenced this issue Apr 10, 2017
…er JS has removed it

Summary:
See #10845

onSizeChanged is enqueueing a runnable from the ui thread that references a shadow view by id on the native modules thread. Since the shadow thread 'runs ahead' of the UI thread (e.g. it has a newer state of the world than the UI thread), this isn't safe. By the time that code block runs, it's possible that an update from JS has already removed that view from the shadow hierarchy (a change which would then propagate to the native hierarchy on the UI thread).

Reviewed By: AaaChiuuu

Differential Revision: D4706521

fbshipit-source-id: 0915f081068709b895f70b2edce12163b39e5456
@grabbou
Copy link
Contributor

grabbou commented Apr 10, 2017 via email

@phamtn8
Copy link

phamtn8 commented May 4, 2017

anyone confirm that this is fixed for RN 0.44?

@zubryan
Copy link

zubryan commented May 10, 2017

Any update? We have the same issue with RN 0.41.2
RN 0.44 is ok?

@astreet
Copy link
Contributor

astreet commented May 10, 2017

Yes, .44 should be fine as it's listed in the release notes: https://github.com/facebook/react-native/releases/tag/v0.44.0

@grabbou grabbou closed this as completed May 11, 2017
frankrod pushed a commit to frankrod/react-native that referenced this issue May 18, 2017
…er JS has removed it

Summary:
See facebook#10845

onSizeChanged is enqueueing a runnable from the ui thread that references a shadow view by id on the native modules thread. Since the shadow thread 'runs ahead' of the UI thread (e.g. it has a newer state of the world than the UI thread), this isn't safe. By the time that code block runs, it's possible that an update from JS has already removed that view from the shadow hierarchy (a change which would then propagate to the native hierarchy on the UI thread).

Reviewed By: AaaChiuuu

Differential Revision: D4706521

fbshipit-source-id: 0915f081068709b895f70b2edce12163b39e5456
@39otrebla
Copy link

Still happening on my side, without using any Modal (I am using react native navigation and its built-in Modal).

platform: Android (min api 21)
react-native: 0.48.3

@couldhll
Copy link

+1

3 similar comments
@mehmetcanker
Copy link

+1

@Shinichi52
Copy link

+1

@etruta
Copy link

etruta commented Dec 19, 2017

+1

@fxalvarezd
Copy link

@astreet not sure if you have any input on this. I have the same issue as @39otrebla described.
It's really random on our end and almost never happens, but when it does it's when transitioning to a screen.
We're running react-native: 0.48.4 and react-native-navigation: ^1.1.300.

ocleo1 pushed a commit to ocleo1/react-native-lets-rock-poc that referenced this issue Mar 8, 2018
@wenkangzhou
Copy link

Still happening in 0.49.5

@8of
Copy link

8of commented Jul 12, 2018

The issue is still here, unfortunately.
React Native 0.55.4, 0.56.0
Android 8

@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
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests