瀏覽代碼

Fix RuntimeException

Fixes a case where `callback` was called twice when something went wrong in the `cp` operation, leading to a `java.lang.RuntimeException: Illegal callback invocation from native module. This callback type only permits a single invocation from native code.`

This is the same fix [as seen in the original repo](https://github.com/wkh237/react-native-fetch-blob/pull/408).
Tom Spencer 6 年之前
父節點
當前提交
e6e27ac0b9
No account linked to committer's email address
共有 1 個文件被更改,包括 10 次插入3 次删除
  1. 10
    3
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 10
- 3
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java 查看文件

548
         path = normalizePath(path);
548
         path = normalizePath(path);
549
         InputStream in = null;
549
         InputStream in = null;
550
         OutputStream out = null;
550
         OutputStream out = null;
551
+        String message = "";
551
 
552
 
552
         try {
553
         try {
553
             if(!isPathExists(path)) {
554
             if(!isPathExists(path)) {
571
                 out.write(buf, 0, len);
572
                 out.write(buf, 0, len);
572
             }
573
             }
573
         } catch (Exception err) {
574
         } catch (Exception err) {
574
-            callback.invoke(err.getLocalizedMessage());
575
+            message += err.getLocalizedMessage();
575
         } finally {
576
         } finally {
576
             try {
577
             try {
577
                 if (in != null) {
578
                 if (in != null) {
580
                 if (out != null) {
581
                 if (out != null) {
581
                     out.close();
582
                     out.close();
582
                 }
583
                 }
583
-                callback.invoke();
584
             } catch (Exception e) {
584
             } catch (Exception e) {
585
-                callback.invoke(e.getLocalizedMessage());
585
+                message += e.getLocalizedMessage();
586
             }
586
             }
587
         }
587
         }
588
+        // Only call the callback once to prevent the app from crashing
589
+        // with an 'Illegal callback invocation from native module' exception.
590
+        if (message != "") {
591
+            callback.invoke(message);
592
+        } else {
593
+            callback.invoke();
594
+        }
588
     }
595
     }
589
 
596
 
590
     /**
597
     /**