From 284d9bd7d3c4166e1ff4d6b1b79b37b3cbe2645e Mon Sep 17 00:00:00 2001 From: Martin Carpella Date: Tue, 19 Apr 2016 22:39:27 +0200 Subject: [PATCH] Add checks for null-SSID (fix for #620) --- .../preferences/WifiSsidPreference.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java b/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java index b8db9454..91481bae 100644 --- a/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java +++ b/src/main/java/com/nutomic/syncthingandroid/preferences/WifiSsidPreference.java @@ -91,11 +91,13 @@ public class WifiSsidPreference extends MultiSelectListPreference { private CharSequence[] extractSsid(WifiConfiguration[] configs, boolean stripQuotes) { CharSequence[] result = new CharSequence[configs.length]; for (int i = 0; i < configs.length; i++) { + // See #620: there may be null-SSIDs + String ssid = configs[i].SSID != null ? configs[i].SSID : ""; // WiFi SSIDs can either be UTF-8 (encapsulated in '"') or hex-strings if (stripQuotes) - result[i] = configs[i].SSID.replaceFirst("^\"", "").replaceFirst("\"$", ""); + result[i] = ssid.replaceFirst("^\"", "").replaceFirst("\"$", ""); else - result[i] = configs[i].SSID; + result[i] = ssid; } return result; } @@ -115,7 +117,10 @@ public class WifiSsidPreference extends MultiSelectListPreference { Arrays.sort(result, new Comparator() { @Override public int compare(WifiConfiguration lhs, WifiConfiguration rhs) { - return lhs.SSID.compareToIgnoreCase(rhs.SSID); + // See #620: There may be null-SSIDs + String l = lhs.SSID != null ? lhs.SSID : ""; + String r = rhs.SSID != null ? rhs.SSID : ""; + return l.compareToIgnoreCase(r); } }); return result;