From 7adac6682014f6e241f71c7cc74b0758a5ce0140 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Tue, 1 Dec 2026 08:54:58 +0530 Subject: [PATCH] fix(sftp): stop crash when stat is called on the root path Creating a folder at the SFTP root stats "/", where splitting the path gave an empty array and threw ArrayIndexOutOfBoundsException on the worker thread, killing the app. Also route unexpected runtime errors in SFTP handlers to the JS error callback instead of crashing. --- .../java/com/foxdebug/acode/sftp/Sftp.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/platforms/android/app/src/main/java/com/foxdebug/acode/sftp/Sftp.java b/platforms/android/app/src/main/java/com/foxdebug/acode/sftp/Sftp.java index f1822e13c..f38a0af44 100644 --- a/platforms/android/app/src/main/java/com/foxdebug/acode/sftp/Sftp.java +++ b/platforms/android/app/src/main/java/com/foxdebug/acode/sftp/Sftp.java @@ -1135,7 +1135,7 @@ public void run() { return; } callback.error("Not connected"); - } catch (IOException | JSONException e) { + } catch (IOException | JSONException | RuntimeException e) { callback.error(errMessage(e)); } } @@ -1186,7 +1186,7 @@ public void run() { } catch ( IOException | URISyntaxException - | SecurityException + | RuntimeException | SshException e ) { Log.e("getFile", "Error downloading file", e); @@ -1386,8 +1386,8 @@ public void run() { "lastModified", fileAttributes.lastModifiedTime() ); - String[] pathSegments = uri.getPath().split("/"); - String filename = pathSegments[pathSegments.length - 1]; + String filename = new File(uri.getPath()).getName(); + if (filename.isEmpty()) filename = "/"; fileStat.put("name", filename); fileStat.put("url", uri.getPath()); @@ -1428,7 +1428,7 @@ public void run() { return; } callback.error("Not connected"); - } catch (URISyntaxException | JSONException | SshException e) { + } catch (URISyntaxException | JSONException | SshException | RuntimeException e) { callback.error(errMessage(e)); } } @@ -1450,7 +1450,7 @@ public void run() { return; } callback.error("Not connected"); - } catch (SftpStatusException | SshException e) { + } catch (SftpStatusException | SshException | RuntimeException e) { callback.error(errMessage(e)); } } @@ -1475,7 +1475,7 @@ public void run() { return; } callback.error("Not connected"); - } catch (SftpStatusException | SshException e) { + } catch (SftpStatusException | SshException | RuntimeException e) { callback.error(errMessage(e)); } } @@ -1518,7 +1518,7 @@ public void run() { } callback.error("Not connected"); } catch ( - SftpStatusException | SshException | TransferCancelledException e + SftpStatusException | SshException | TransferCancelledException | RuntimeException e ) { callback.error(errMessage(e)); } @@ -1543,7 +1543,7 @@ public void run() { return; } callback.error("Not connected"); - } catch (SftpStatusException | SshException e) { + } catch (SftpStatusException | SshException | RuntimeException e) { callback.error(errMessage(e)); } } @@ -1564,7 +1564,7 @@ public void run() { return; } callback.error("Not connected"); - } catch (SftpStatusException | SshException e) { + } catch (SftpStatusException | SshException | RuntimeException e) { callback.error(errMessage(e)); } }