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: "FATAL EXCEPTION: mqt_js" / Error calling function: RCTDeviceEventEmitter:emit / - malformed JSON parsing in RN's android native code

See original GitHub issue

Description

Calling fetch() and expecting JSON results (i.e. using response.json()) will crash if server sends malformed JSON. Error/logging system prints “Failed to create String from JSON:” and then does NOT print the JSON (the problem this ticket IS about).

https://github.com/facebook/react-native/issues/9117 promised to fix this, but did not.

Reproduction

Call fetch() and then response.json() with a server that returns bad JSON.

Additional Information

  • React Native version: 0.36
  • Platform: Android
  • Operating System: MacOS

Here’s an example log:

11-04 13:39:46.611  3509  3509 D EPDG -- [EPDGService]: onDataActivity: direction=3
11-04 13:39:46.611  7541  7836 D NetworkController.MobileSignalController(0/2): onDataActivity: direction=3
11-04 13:39:46.781 17917 17917 V MediaPlayer-JNI: getCurrentPosition: 617 (msec)
11-04 13:39:47.031 17917 17917 V MediaPlayer-JNI: getCurrentPosition: 617 (msec)
11-04 13:39:47.281 17917 17917 V MediaPlayer-JNI: getCurrentPosition: 617 (msec)
11-04 13:39:47.541 17917 17917 V MediaPlayer-JNI: getCurrentPosition: 617 (msec)
11-04 13:39:47.641  3509  3509 D EPDG -- [EPDGService]: onDataActivity: direction=1
11-04 13:39:47.641  7541  7836 D NetworkController.MobileSignalController(0/2): onDataActivity: direction=1
11-04 13:39:47.791 17917 17917 V MediaPlayer-JNI: getCurrentPosition: 617 (msec)
11-04 13:39:47.821 17917 17976 I System.out: (HTTPLog)-Static: isSBSettingEnabled false
11-04 13:39:47.821 17917 17976 I System.out: (HTTPLog)-Static: isSBSettingEnabled false
11-04 13:39:47.821  3079  3883 D EnterpriseController: netId is 0
11-04 13:39:47.821  3079  3883 D Netd    : getNetworkForDns: using netid 507 for uid 10726
11-04 13:39:47.821 17917 17968 E AndroidRuntime: FATAL EXCEPTION: mqt_js
11-04 13:39:47.821 17917 17968 E AndroidRuntime: Process: com.stardust, PID: 17917
11-04 13:39:47.821 17917 17968 E AndroidRuntime: java.lang.RuntimeException: Error calling function: RCTDeviceEventEmitter:emit
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:739)
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:95)
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:158)
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:818)
11-04 13:39:47.821 17917 17968 E AndroidRuntime: Caused by: java.lang.RuntimeException: Failed to create String from JSON: 
11-04 13:39:47.821 17917 17968 E AndroidRuntime: 	... 7 more
11-04 13:39:47.841  3509  4040 W ActivityManager:   Force finishing activity com.stardust/.MainActivity
11-04 13:39:47.851  3509  4040 D FocusedStackFrame: Set to : 0
11-04 13:39:47.851  3509  4040 D InputDispatcher: Focused application set to: xxxx
11-04 13:39:47.861  3509  4040 D InputDispatcher: Focus left window: 17917
11-04 13:39:47.861  3509  3638 D PointerIcon: setMouseIconStyle1 pointerType: 1001 iconType:101 flag:0 pid:3509 uid:1000
11-04 13:39:47.861  3509  3638 D PointerIcon: setMouseCustomIcon IconType is same.101
11-04 13:39:47.931  3509 18371 E android.os.Debug: ro.product_ship = true
11-04 13:39:47.931  3509 18371 E android.os.Debug: ro.debug_level = 0x4f4c
11-04 13:39:47.931  3509 18371 E android.os.Debug: sys.mobilecare.preload = false
11-04 13:39:47.971  3509  3610 D ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{5822614 V.E...... R.....I. 0,0-0,0}
11-04 13:39:47.981  3509  3610 D ISSUE_DEBUG: InputChannelName : 1cdbcb2 Application Error: com.stardust
11-04 13:39:47.981  3509  3610 V MARsPolicyManager: handelAlertToastWindowStarted pkgName = android
11-04 13:39:47.981  3509  3610 D InputDispatcher: Focus entered window: 3509
11-04 13:39:47.981  3509  3638 D PointerIcon: setMouseIconStyle1 pointerType: 1001 iconType:101 flag:0 pid:3509 uid:1000
11-04 13:39:47.981  3509  3638 D PointerIcon: setMouseCustomIcon IconType is same.101
11-04 13:39:47.991  3067  3067 I SurfaceFlinger: id=2946 createSurf (193x193),1 flag=4, ttardust
11-04 13:39:48.001 18372 18372 E Zygote  : v2
11-04 13:39:48.001 18372 18372 I libpersona: KNOX_SDCARD checking this for 1000
11-04 13:39:48.001  3509  3609 I ActivityManager: Start proc 18372:com.samsung.android.sm/1000 for broadcast-3 com.samsung.android.sm/.common.SmartManagerReceiver
11-04 13:39:48.001 18372 18372 I libpersona: KNOX_SDCARD not a persona

Questions:

  • What do we have to do to actually include the JSON so we can get to the bottom of this?
  • Why does it say “… 7 more” ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:49 (8 by maintainers)

github_iconTop GitHub Comments

8reactions
teyoucommented, Aug 22, 2017

it happens when I do

fetch('http://ideapit.net/filedata/201203/9fi32220120330230712.jpg')

and it’s only crash on Android release mode.

Hence, I switched to axios and since then no more crash!

7reactions
sammacbethcommented, Jan 26, 2018

This expo app demonstrates the issue, and that the same code works on iOS: https://snack.expo.io/HJkNh3_Sz

Deeper analysis shows that the android network module retrieves the data and sends to the NativeEventEmitter: https://github.com/facebook/react-native/blob/3fc33bb54fc5dcf7ef696fe245addc320f85a269/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java#L390

It is then somewhere in the bridge code where the crash occurs. In the debugger I don’t get any further than here: https://github.com/facebook/react-native/blob/3fc33bb54fc5dcf7ef696fe245addc320f85a269/ReactAndroid/src/main/java/com/facebook/react/bridge/JavaScriptModuleRegistry.java#L91-L97

where the Java arguments are converted to a C++ object for the invocation of the bridged function. The crash stacktrace comes from the C++ jsc helper code: https://github.com/facebook/react-native/blob/3fc33bb54fc5dcf7ef696fe245addc320f85a269/ReactCommon/jschelpers/Value.cpp#L69-L77

As the crash is in the JS bridge, this bug could also affect other native modules which do not sanitise data before sending it to Javascript.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Android JSON parsing using Retrofit and GSON gets ...
The issue here as far as I can tell is that the object you provide to retrofit doesn't match the json you provide...
Read more >
MalformedJsonException - Android Developers
Thrown when a reader encounters malformed JSON. Some syntax errors can be ignored by calling ... Returns a hash code value for the...
Read more >
Receiving a Malformed JSON Error When Using API Doc
Cause. The malformed JSON error means that the format of the API call is incorrect.
Read more >
Moshi — modern JSON serialization library for Java and Kotlin
Moshi is a modern JSON serialization library for Java and Kotlin. It makes the process of Parsing and Converting a JSON object into...
Read more >
JSON parsing natively in jQuery 1.4 and updates - BigBinary
The jQuery code to handle JSON data looks like this. 1$.ajax({ 2 type: "GET", 3 url: "test.js", 4 dataType: "json", 5 success: function...
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