From 921a5d1aa8898c8c6f0e75abe8d8e43b95d7062b Mon Sep 17 00:00:00 2001 From: Sean Gilligan Date: Tue, 2 Jul 2019 21:08:27 -0700 Subject: [PATCH] Fix NPE in o.b.c.Utils runtime and os detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If getProperty returns null calling toLowerCase results in NPE. Instead we’ll use a default value and check for .equals(“”) in the following if. --- core/src/main/java/org/bitcoinj/core/Utils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Utils.java b/core/src/main/java/org/bitcoinj/core/Utils.java index 7dfab6f8..a28c4e66 100644 --- a/core/src/main/java/org/bitcoinj/core/Utils.java +++ b/core/src/main/java/org/bitcoinj/core/Utils.java @@ -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;