Skip to content

Commit e6e27ac

Browse files
authored
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](wkh237#408).
1 parent 981627e commit e6e27ac

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ static void cp(String path, String dest, Callback callback) {
548548
path = normalizePath(path);
549549
InputStream in = null;
550550
OutputStream out = null;
551+
String message = "";
551552

552553
try {
553554
if(!isPathExists(path)) {
@@ -571,7 +572,7 @@ static void cp(String path, String dest, Callback callback) {
571572
out.write(buf, 0, len);
572573
}
573574
} catch (Exception err) {
574-
callback.invoke(err.getLocalizedMessage());
575+
message += err.getLocalizedMessage();
575576
} finally {
576577
try {
577578
if (in != null) {
@@ -580,11 +581,17 @@ static void cp(String path, String dest, Callback callback) {
580581
if (out != null) {
581582
out.close();
582583
}
583-
callback.invoke();
584584
} catch (Exception e) {
585-
callback.invoke(e.getLocalizedMessage());
585+
message += e.getLocalizedMessage();
586586
}
587587
}
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+
}
588595
}
589596

590597
/**

0 commit comments

Comments
 (0)