Handle nullable sysprop for tryParseBoolean
When mocking SystemProperties, reading a boolean value fails because the
code tries to convert it to lowercase without a null check. This changes
it so that null input is returned as a null Boolean before the
toLowerCase call.
Change-Id: Ia595341409bd927f4fa51c918fe4a052bb2bcdce
diff --git a/JavaGen.cpp b/JavaGen.cpp
index fa4c106..55d5ae4 100644
--- a/JavaGen.cpp
+++ b/JavaGen.cpp
@@ -54,6 +54,7 @@
constexpr const char* kJavaParsersAndFormatters =
R"s(private static Boolean tryParseBoolean(String str) {
+ if (str == null) return null;
switch (str.toLowerCase(Locale.US)) {
case "1":
case "true":
diff --git a/tests/JavaGenTest.cpp b/tests/JavaGenTest.cpp
index 6ae0474..be04a4f 100644
--- a/tests/JavaGenTest.cpp
+++ b/tests/JavaGenTest.cpp
@@ -122,6 +122,7 @@
private TestProperties () {}
private static Boolean tryParseBoolean(String str) {
+ if (str == null) return null;
switch (str.toLowerCase(Locale.US)) {
case "1":
case "true":
@@ -342,6 +343,7 @@
private TestProperties () {}
private static Boolean tryParseBoolean(String str) {
+ if (str == null) return null;
switch (str.toLowerCase(Locale.US)) {
case "1":
case "true":