handlebars.java
handlebars.java copied to clipboard
The nashorn is being used but not included in java 15+
In the handlebars.java 4.3.0
the problem with java 15+ supposed to be solved but the code below is still trying to get instance of nashorn
script engine, which is not included in jdk any more.
https://github.com/jknack/handlebars.java/blob/ef79693a7d49ccfe28da7da12355db331a0cb317/handlebars/src/main/java/com/github/jknack/handlebars/helper/DefaultHelperRegistry.java#L302
The code is being referenced via the registerHelpers
method of Handlebars
when a js file is being used as the helper source.
Here is the pull request which addressed the issue #867
The following is the stacktrace which resulted by calling registerHelpers
method.
java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.put(String, Object)" because "this.engine" is null
at com.github.jknack.handlebars.helper.DefaultHelperRegistry.engine(DefaultHelperRegistry.java:304)
at com.github.jknack.handlebars.helper.DefaultHelperRegistry.registerHelpers(DefaultHelperRegistry.java:193)
at com.github.jknack.handlebars.helper.DefaultHelperRegistry.registerHelpers(DefaultHelperRegistry.java:173)
at com.github.jknack.handlebars.Handlebars.registerHelpers(Handlebars.java:750)
Right. Are you building with Maven? There is a maven profile for Java 15: https://github.com/jknack/handlebars.java/blob/master/handlebars/pom.xml#L381
The profile has the required dependency. Build is running without issue against Java 15. See here https://github.com/jknack/handlebars.java/actions/runs/1331083456
If you still have the issue try adding the dependency manually: https://search.maven.org/artifact/org.openjdk.nashorn/nashorn-core/15.3/jar
Hi @jknack,
same issue here with Java 15 and Java 17 invoking com.github.jknack.handlebars.Handlebars.registerHelpers
java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.put(String, Object)" because "this.engine" is null
It's a spring boot 2.5.8 project.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.8</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars-jackson2</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars-helpers</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.openjdk.nashorn</groupId>
<artifactId>nashorn-core</artifactId>
<version>15.3</version>
</dependency>
@comoroberto where you able to resolve your issue?
I am using handlebars as part of git-changelog-lib and have added nashorn
manually as well. Build is still failing with the mentioned NPE though.
@comoroberto where you able to resolve your issue?
I am using handlebars as part of git-changelog-lib and have added
nashorn
manually as well. Build is still failing with the mentioned NPE though.
Resolved. I had to clean my local .m2 repository and perform some maven clean on the project.
I am using handlebars as part of git-changelog-lib with java 11. Build is still failing with the NPE .
[ERROR] GitChangelog java.lang.NullPointerException at com.github.jknack.handlebars.helper.DefaultHelperRegistry.engine (DefaultHelperRegistry.java:304) at com.github.jknack.handlebars.helper.DefaultHelperRegistry.registerHelpers (DefaultHelperRegistry.java:193) at com.github.jknack.handlebars.Handlebars.registerHelpers (Handlebars.java:859)
but nashorn is a part of java 11
It looks like this was originally fixed for Java 11 on #702 and #731.
However that change was reverted in 865f2d7f3c91a76a41cf855e7fac1e8a112c3056 and 4.3.0, 4.3.1 no longer work on Java 11 giving the original NPE again. Having to stay on 4.2.1 currently.