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

An error occurred while executing doInBackground(), Caused by java.lang.NullPointerException com.microsoft.codepush.react.FileUtils.copyDirectoryContents

Open natioskar opened this issue 3 years ago • 16 comments

Steps to Reproduce

I wasn't able to reproduce it myself due to lack of this kind of device, but according to the Crashlytics & Sentry stack trace its only happening on Huawei P30 lite right after the code push update check (with no new pending updates)

Expected Behavior

Just normal update check and continue app loading, with the result of no new update

Actual Behavior

App crashed with the following -

Fatal Exception: java.lang.RuntimeException
An error occurred while executing doInBackground()
    android.os.AsyncTask$4.done (AsyncTask.java:399)
    java.lang.Thread.run (Thread.java:929)
java.io.File.<init> (File.java:283)
com.microsoft.codepush.react.FileUtils.copyDirectoryContents (FileUtils.java:19)
com.microsoft.codepush.react.CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage (CodePushUpdateUtils.java:100)
com.microsoft.codepush.react.CodePushUpdateManager.downloadPackage (CodePushUpdateManager.java:242)
com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground (CodePushNativeModule.java:290)
com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground (CodePushNativeModule.java:284)
android.os.AsyncTask$3.call (AsyncTask.java:378)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
java.lang.Thread.run (Thread.java:929)

Reproducible Demo

I don't have a reproducible Demo, but the way I use code push -

CodePush({
  checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
  installMode: CodePush.InstallMode.ON_NEXT_RESUME,
})

Environment

  • react-native-code-push version: 7.0.1
  • react-native version: 0.64.0
  • iOS/Android/Windows version: Android 10
  • Does this reproduce on a debug build or release build? release
  • Does this reproduce on a simulator, or only on a physical device? physical device - Huawei P30 lite

Sorry for the lack of reproducible demo and more specific steps, this only started when we rolled out to production

natioskar avatar May 09 '21 17:05 natioskar

We received the same error in Bugsnag, on a Samsung Galaxy A5(2017) (SM-A520F) on Android 8.0.0

java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:353)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

Caused by: java.lang.NullPointerException
        at java.io.File.<init>(File.java:282)
        at com.microsoft.codepush.react.FileUtils.copyDirectoryContents(FileUtils.java:19)
        at com.microsoft.codepush.react.CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage(CodePushUpdateUtils.java:100)
        at com.microsoft.codepush.react.CodePushUpdateManager.downloadPackage(CodePushUpdateManager.java:228)
        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:290)
        at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

tom-sherman avatar May 10 '21 10:05 tom-sherman

Seems to be happening for me as well. 2 isolated events in devices from different manufacturers. Same stack trace as posted above.

Screen Shot 2021-05-11 at 3 59 38 pm

rodperottoni avatar May 11 '21 06:05 rodperottoni

We are receiving the same error in Crashlytics for different devices (Samsung, Motorola, Xiaomi, LGE) on Android 8, 9, 10 and 11.

  • react-native-code-push version: 6.2.1
  • react-native version: 0.61.5

Fatal Exception: java.lang.RuntimeException An error occurred while executing doInBackground() android.os.AsyncTask$4.done (AsyncTask.java:399) java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383) java.util.concurrent.FutureTask.setException (FutureTask.java:252) java.util.concurrent.FutureTask.run (FutureTask.java:271) java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167) java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641) java.lang.Thread.run (Thread.java:919)

Exception java.io.File.<init> (File.java:283) com.microsoft.codepush.react.FileUtils.copyDirectoryContents (FileUtils.java:19) com.microsoft.codepush.react.CodePushUpdateUtils.copyNecessaryFilesFromCurrentPackage (CodePushUpdateUtils.java:100) com.microsoft.codepush.react.CodePushUpdateManager.downloadPackage (CodePushUpdateManager.java:228) com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground (CodePushNativeModule.java:217) com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground (CodePushNativeModule.java:211)

HernanAlbertario avatar May 13 '21 15:05 HernanAlbertario

I have the exact same error, for those devices at the moment image

christophemenager avatar May 22 '21 08:05 christophemenager

Update (12/6) Its been a month now, and the issue is not recreating for me (but still no answer from Microsoft guys).. can I assume is was it was a single case? is it still happening to you guys?

natioskar avatar Jun 11 '21 21:06 natioskar

Same here, happened twice on the 10th of May and then never again...

tom-sherman avatar Jun 12 '21 20:06 tom-sherman

Same here, the last time it happened was on 12th of May.

HernanAlbertario avatar Jun 14 '21 13:06 HernanAlbertario

Just had this issue reported from Sentry, occurred Aug 7, 2021 1:22:58 AM UTC. Identical stack trace as previous comments, affected device was Samsung SM-T395, Android 9.

Same as original author, there would have been NO update available.

ted-nz avatar Aug 07 '21 11:08 ted-nz

Getting this error as well..any updates on this?

nikhilk1993 avatar Aug 12 '21 10:08 nikhilk1993

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs within 15 days of this comment.

ghost avatar Dec 13 '21 13:12 ghost

This is still happening for us, albeit very infrequently.

tom-sherman avatar Dec 13 '21 13:12 tom-sherman

We mitigated the issue by patching FileUtils.java which is located in 
node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java

@geof90 @LittleXianyu @andreidubov Please include the following code in the code base or figure out the root cause of the issue.

[Do this after npm ci or install]

try {
    sourceDir = new File(sourceDirectoryPath);
    destDir = new File(destinationDirectoryPath);
} catch (NullPointerException e) {
    throw new CodePushUnknownException("Error creating directories", e);
}

https://github.com/microsoft/react-native-code-push/blob/3f6219cca18b2aced4381935ca00a08cc54e3a13/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java#L19

simonchengbbyca avatar Dec 17 '21 00:12 simonchengbbyca

java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$4.done(AsyncTask.java:415) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:920) Caused by: java.lang.NullPointerException at java.io.File.(File.java:323) at com.microsoft.codepush.react.FileUtils.moveFile(FileUtils.java:105) at com.microsoft.codepush.react.CodePushUpdateManager.downloadPackage(CodePushUpdateManager.java:303) at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:290) at com.microsoft.codepush.react.CodePushNativeModule$3.doInBackground(CodePushNativeModule.java:284) at android.os.AsyncTask$3.call(AsyncTask.java:394) at java.util.concurrent.FutureTask.run(FutureTask.java:266)

"react-native": "0.66.4", "react-native-code-push": "^7.0.4",

jamninetyfive avatar Apr 27 '22 05:04 jamninetyfive

Any update on this issue ? We are also facing the same. This happened once and not repeated for the users.

Screenshot 2022-06-06 at 1 47 07 PM Screenshot 2022-06-06 at 1 45 44 PM

manish-patwari avatar Jun 06 '22 08:06 manish-patwari

This issue popped up for the first time 2 days ago (our app is ~2 years old) after an OTA update.

image image

A corrupted download of the zip file due to network issues on microsoft servers?

Minishlink avatar Oct 13 '22 12:10 Minishlink

Facing the same issue, any fix?

HimanshuNarang avatar Jan 29 '24 06:01 HimanshuNarang