From 44c7de515a59744eb12a75affe75fad89700ef87 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Tue, 2 Sep 2014 17:24:14 +0200 Subject: [PATCH] Fixes some small potential crashes when user input is incorrect. --- .../core/app/settings/ApplicationSettings.java | 10 ++++++++++ .../org/transdroid/core/gui/DetailsFragment.java | 13 ++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/src/org/transdroid/core/app/settings/ApplicationSettings.java b/core/src/org/transdroid/core/app/settings/ApplicationSettings.java index f0726df1..d499225e 100644 --- a/core/src/org/transdroid/core/app/settings/ApplicationSettings.java +++ b/core/src/org/transdroid/core/app/settings/ApplicationSettings.java @@ -148,6 +148,16 @@ public class ApplicationSettings { String localPort = prefs.getString("server_localport_" + order, ""); if (localPort.equals("")) localPort = port; // Default to the normal (non-local) port + try { + Integer.parseInt(port); + } catch (NumberFormatException e) { + port = Integer.toString(Daemon.getDefaultPortNumber(type, ssl)); + } + try { + Integer.parseInt(localPort); + } catch (NumberFormatException e) { + localPort = port; + } return new ServerSetting(order, prefs.getString("server_name_" + order, null), diff --git a/core/src/org/transdroid/core/gui/DetailsFragment.java b/core/src/org/transdroid/core/gui/DetailsFragment.java index 7dbc940c..f6fd5516 100644 --- a/core/src/org/transdroid/core/gui/DetailsFragment.java +++ b/core/src/org/transdroid/core/gui/DetailsFragment.java @@ -444,11 +444,14 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen andftpStart.putExtra("local_folder", "/sdcard/Download"); for (int f = 0; f < checked.size(); f++) { String file = checked.get(f).getRelativePath(); - // If the file is directly in the root, AndFTP fails if we supply the proper path (like /file.pdf) - // Work around this bug by removing the leading / if no further directories are used in the path - if (file.startsWith("/") && file.indexOf("/", 1) < 0) - file = file.substring(1); - andftpStart.putExtra("remote_file" + (f + 1), file); + if (file != null) { + // If the file is directly in the root, AndFTP fails if we supply the proper path (like + // /file.pdf) + // Work around this bug by removing the leading / if no further directories are used in the path + if (file.startsWith("/") && file.indexOf("/", 1) < 0) + file = file.substring(1); + andftpStart.putExtra("remote_file" + (f + 1), file); + } } if (andftpStart.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(andftpStart);