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