Fix NPE in o.b.c.Utils runtime and os detection

If getProperty returns null calling toLowerCase results in NPE. Instead
we’ll use a default value and check for .equals(“”) in the following if.
This commit is contained in:
Sean Gilligan
2019-07-02 21:08:27 -07:00
committed by Andreas Schildbach
parent 5bb5de395e
commit 921a5d1aa8

View File

@@ -561,8 +561,8 @@ public class Utils {
private static Runtime runtime = null; private static Runtime runtime = null;
private static OS os = null; private static OS os = null;
static { static {
String runtimeProp = System.getProperty("java.runtime.name").toLowerCase(Locale.US); String runtimeProp = System.getProperty("java.runtime.name", "").toLowerCase(Locale.US);
if (runtimeProp == null) if (runtimeProp.equals(""))
runtime = null; runtime = null;
else if (runtimeProp.contains("android")) else if (runtimeProp.contains("android"))
runtime = Runtime.ANDROID; runtime = Runtime.ANDROID;
@@ -573,8 +573,8 @@ public class Utils {
else else
log.info("Unknown java.runtime.name '{}'", runtimeProp); log.info("Unknown java.runtime.name '{}'", runtimeProp);
String osProp = System.getProperty("os.name").toLowerCase(Locale.US); String osProp = System.getProperty("os.name", "").toLowerCase(Locale.US);
if (osProp == null) if (osProp.equals(""))
os = null; os = null;
else if (osProp.contains("linux")) else if (osProp.contains("linux"))
os = OS.LINUX; os = OS.LINUX;