From 1089e11f39be2bbacb495601419166395b99e6b7 Mon Sep 17 00:00:00 2001 From: Vanda Cabanova Date: Thu, 7 Sep 2023 15:22:37 +0200 Subject: [PATCH] Work around the Android Java version issue Android does not use a particular Java version and because of that the property value is 0.9 which results in a NumberFormatException. As before, Android should default to 8. --- .../com/github/jknack/handlebars/Handlebars.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java index a63f1d1e4..3e1f48a66 100644 --- a/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java +++ b/handlebars/src/main/java/com/github/jknack/handlebars/Handlebars.java @@ -248,7 +248,17 @@ public static CharSequence escapeExpression(final CharSequence input) { static int javaVersion() { String version = System.getProperty("java.specification.version").trim(); - return Integer.parseInt(version.replace(VERSION_PREFIX, "")); + try { + return Integer.parseInt(version.replace(VERSION_PREFIX, "")); + } catch (NumberFormatException ex) { + // a workaround for Android apps where the [java.specification.version] property is set to 0.9 + // https://developer.android.com/reference/java/lang/System#getProperties() + if (version.equals("0.9")) { + return 8; + } else { + throw ex; + } + } } /**