handlebars.java icon indicating copy to clipboard operation
handlebars.java copied to clipboard

NumberFormatException for ValueResolver.getDefaultResolvers on Android

Open kingargyle opened this issue 3 years ago • 5 comments

When running handlebars on Android as part of WireMock. Getting a NumberFormatException when Handlebars.Util tries to get the javaVersion(). The value is returned as a string "0.9" in Android.

static int javaVersion() { String version = System.getProperty("java.specification.version").trim(); return Integer.parseInt(version.replace(VERSION_PREFIX, "")); }

If for some reason that the Integer can't be parsed, we get a NumberFormat exception. If this is the case can a default version be provided/. Or have Value Resolver catch the exception and return the default list of MapValueResolver, JavaBeanValueResolver instead of crashing.

kingargyle avatar Oct 28 '22 19:10 kingargyle

This has become a larger problem with older versions of Wiremock using dependencies with CVEs open against them, nessicating an upgrade which would entail the use of this version of Handlebars - which then fails due to this issue.

inktomi avatar Jul 28 '23 20:07 inktomi

@jknack do you have any plan to fix this issue? It's not possible to use newer versions of this library on Android where the older versions are facing open CVEs.

vandac avatar Sep 07 '23 12:09 vandac

The previous implementation used a property that was probably always 0. Now it uses a property that is always 0.9 if I am not mistaken. https://developer.android.com/reference/java/lang/System#getProperties()

vandac avatar Sep 07 '23 12:09 vandac

I have made an attempt to work around this issue. Please review this PR https://github.com/jknack/handlebars.java/pull/1074.

vandac avatar Sep 07 '23 13:09 vandac

it seems to be the same problem as #937. I'm also struggling with this problem, and I hope it gets resolved quickly.

zmunm avatar Nov 21 '23 10:11 zmunm