NPE when checking subnet during Swap
Not sure how reproduceable this is for others, because it only occurs on my 5.0 device, not my 4.4 device. However, if:
- I'm connected to a wifi network
- I open F-Droid
- Start swap activity
- It will hang, then crash with the following log:
E FATAL EXCEPTION: AsyncTask #2
E Process: org.fdroid.fdroid, PID: 24766
E java.lang.RuntimeException: An error occured while executing doInBackground()
E at android.os.AsyncTask$3.done(AsyncTask.java:300)
E at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
E at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
E at java.util.concurrent.FutureTask.run(FutureTask.java:242)
E at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
E at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E at java.lang.Thread.run(Thread.java:818)
E Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.lang.CharSequence.length()' on a null object reference
E at java.util.regex.Matcher.reset(Matcher.java:177)
E at java.util.regex.Matcher.<init>(Matcher.java:90)
E at java.util.regex.Pattern.matcher(Pattern.java:297)
E at org.apache.commons.net.util.SubnetUtils.toInteger(SubnetUtils.java:248)
E at org.apache.commons.net.util.SubnetUtils.toCidrNotation(SubnetUtils.java:325)
E at org.apache.commons.net.util.SubnetUtils.<init>(SubnetUtils.java:63)
E at org.fdroid.fdroid.net.WifiStateChangeService$WaitForWifiAsyncTask.doInBackground(WifiStateChangeService.java:90)
E at org.fdroid.fdroid.net.WifiStateChangeService$WaitForWifiAsyncTask.doInBackground(WifiStateChangeService.java:71)
E at android.os.AsyncTask$2.call(AsyncTask.java:288)
E at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E ... 4 more
This happens every time on this device. I can confirm that when debugging, the following code ends up with local netmask
variable being null
.
if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
wifiInfo = wifiManager.getConnectionInfo();
FDroidApp.ipAddressString = formatIpAddress(wifiInfo.getIpAddress());
String netmask = formatIpAddress(wifiManager.getDhcpInfo().netmask);
if (!TextUtils.isEmpty(FDroidApp.ipAddressString))
FDroidApp.subnetInfo = new SubnetUtils(FDroidApp.ipAddressString, netmask).getInfo();
I'm happy to submit a fix with a null check in there, but I don't fully understand what the ramifications of a null
netmask is. Perhaps there is a more robust way to deal with it?