From 6e137dfd672ff9d2ed67e8cdfab3eafe41e143e5 Mon Sep 17 00:00:00 2001 From: Bowie Chen Date: Tue, 29 Oct 2019 21:17:56 +0800 Subject: [PATCH] Add null-guards for IP address. --- .../asynchronous/services/ftp/FtpService.java | 3 +++ .../ui/notifications/FtpNotification.java | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpService.java b/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpService.java index c24c7bd87..144ab123c 100644 --- a/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpService.java +++ b/app/src/main/java/com/amaze/filemanager/asynchronous/services/ftp/FtpService.java @@ -320,6 +320,9 @@ public class FtpService extends Service implements Runnable { Enumeration addresses = netinterface.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); + if (address == null) { + continue; + } if(address.getHostAddress().startsWith(WIFI_AP_ADDRESS_PREFIX) && isEnabledWifiHotspot(context)) return address; diff --git a/app/src/main/java/com/amaze/filemanager/ui/notifications/FtpNotification.java b/app/src/main/java/com/amaze/filemanager/ui/notifications/FtpNotification.java index c8c0713b7..de1dcc8f4 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/notifications/FtpNotification.java +++ b/app/src/main/java/com/amaze/filemanager/ui/notifications/FtpNotification.java @@ -88,12 +88,17 @@ public class FtpNotification extends BroadcastReceiver { InetAddress address = FtpService.getLocalInetAddress(context); - String iptext = (secureConnection ? FtpService.INITIALS_HOST_SFTP : FtpService.INITIALS_HOST_FTP) - + address.getHostAddress() + ":" - + port + "/"; + String address_text = "Address not found"; + + if (address != null) { + address_text = (secureConnection ? FtpService.INITIALS_HOST_SFTP : FtpService.INITIALS_HOST_FTP) + + address.getHostAddress() + ":" + + port + "/"; + } + NotificationCompat.Builder builder = buildNotification(context, - R.string.ftp_notif_title, context.getString(R.string.ftp_notif_text, iptext), noStopButton); + R.string.ftp_notif_title, context.getString(R.string.ftp_notif_text, address_text), noStopButton); notificationManager.notify(NotificationConstants.FTP_ID, builder.build()); }