react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

CodePushMalformedDataException: Unable to parse contents of files/CodePush/codepush.json, the file may be corrupted

Open MAKARD opened this issue 1 year ago • 2 comments

Steps to Reproduce

  1. Make android app read corrupted codepush.json
  2. Run the app
  3. Observe the crash

Expected Behavior

App removes corrupted codepush.json file and triggers codepush update flow again

Actual Behavior

App crashes

java.lang.RuntimeException: Unable to create application com.myapp.MainApplication: com.microsoft.codepush.react.CodePushMalformedDataException: Unable to parse contents of /data/user/0/com.myapp/files/CodePush/codepush.json, the file may be corrupted.
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7608)
  at android.app.ActivityThread.access$2600(ActivityThread.java:260)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2435)
  at android.os.Handler.dispatchMessage(Handler.java:110)
  at android.os.Looper.loop(Looper.java:219)
  at android.app.ActivityThread.main(ActivityThread.java:8668)
  at java.lang.reflect.Method.invoke(Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
Caused by: com.microsoft.codepush.react.CodePushMalformedDataException: Unable to parse contents of /data/user/0/com.myapp/files/CodePush/codepush.json, the file may be corrupted.
  at com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile(CodePushUtils.java:200)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageInfo(CodePushUpdateManager.java:59)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageHash(CodePushUpdateManager.java:109)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackage(CodePushUpdateManager.java:119)
  at com.microsoft.codepush.react.CodePush.initializeUpdateAfterRestart(CodePush.java:298)
  at com.microsoft.codepush.react.CodePush.<init>(CodePush.java:88)
  at com.facebook.react.PackageList.getPackages(PackageList.java:146)
  at com.myapp.MainApplication$1.getPackages(MainApplication.java:46)
  at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:86)
  at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:42)
  at com.myapp.MainApplication.onCreate(MainApplication.java:99)
  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1202)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7588)
  at android.app.ActivityThread.access$2600(ActivityThread.java:260)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2435)
  at android.os.Handler.dispatchMessage(Handler.java:110)
  at android.os.Looper.loop(Looper.java:219)
  at android.app.ActivityThread.main(ActivityThread.java:8668)
  at java.lang.reflect.Method.invoke(Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
Caused by: org.json.JSONException: Value  of type java.lang.String cannot be converted to JSONObject
  at org.json.JSON.typeMismatch(JSON.java:112)
  at org.json.JSONObject.<init>(JSONObject.java:168)
  at org.json.JSONObject.<init>(JSONObject.java:181)
  at com.microsoft.codepush.react.CodePushUtils.getJsonObjectFromFile(CodePushUtils.java:197)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageInfo(CodePushUpdateManager.java:59)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackageHash(CodePushUpdateManager.java:109)
  at com.microsoft.codepush.react.CodePushUpdateManager.getCurrentPackage(CodePushUpdateManager.java:119)
  at com.microsoft.codepush.react.CodePush.initializeUpdateAfterRestart(CodePush.java:298)
  at com.microsoft.codepush.react.CodePush.<init>(CodePush.java:88)
  at com.facebook.react.PackageList.getPackages(PackageList.java:146)
  at com.myapp.MainApplication$1.getPackages(MainApplication.java:46)
  at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:86)
  at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:42)
  at com.myapp.MainApplication.onCreate(MainApplication.java:99)
  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1202)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7588)
  at android.app.ActivityThread.access$2600(ActivityThread.java:260)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2435)
  at android.os.Handler.dispatchMessage(Handler.java:110)
  at android.os.Looper.loop(Looper.java:219)
  at android.app.ActivityThread.main(ActivityThread.java:8668)
  at java.lang.reflect.Method.invoke(Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

Reproducible Demo

Environment

  • react-native-code-push version: 8.1.0
  • react-native version: 0.72.6
  • iOS/Android/Windows version: Android 11
  • Does this reproduce on a debug build or release build: Both
  • Does this reproduce on a simulator, or only on a physical device: Both

MAKARD avatar Feb 01 '24 09:02 MAKARD

Hi @MAKARD , thank you for this report and the contribution PR! Please find my comment in PR, I suggested a small tweak.

DmitriyKirakosyan avatar Mar 05 '24 09:03 DmitriyKirakosyan

Thanks @DmitriyKirakosyan for the feedback, I've provided a fix for the comment

MAKARD avatar Mar 05 '24 19:03 MAKARD