简体   繁体   中英

Upgrade to Java 17 throws java.lang.RuntimeException: Error creating extended parser class: Could not determine whether class has already been loaded

I am using jtwig lib and the code was working fine but when we upgraded to Java 17, I am getting the below mention runtime exception.

Below is the method and throws RuntimeException while calling template.render()

 String renderDescription(String templatePath,String userId, String caseId) {

       JtwigTemplate template = 
       JtwigTemplate.classpathTemplate(templatePath);

       JtwigModel model = JtwigModel.newModel()
                         .with("userId", userId)
                        .with("caseId", caseId)
                        .with("statusPageUrlTemplate", 
                         config.getStatusPageUrlTemplate());

       return template.render(model);
 }
java.lang.RuntimeException: Error creating extended parser class: Could not determine whether class 'org.jtwig.parser.parboiled.base.BooleanParser$$parboiled' has already been loaded
    at org.parboiled.Parboiled.createParser(Parboiled.java:58)
    at org.jtwig.parser.parboiled.ParserContext.instance(ParserContext.java:31)
    at org.jtwig.parser.parboiled.ParboiledJtwigParser.parse(ParboiledJtwigParser.java:37)
    at org.jtwig.parser.cache.InMemoryConcurrentPersistentTemplateCache.get(InMemoryConcurrentPersistentTemplateCache.java:39)
    at org.jtwig.parser.CachedJtwigParser.parse(CachedJtwigParser.java:19)
    at org.jtwig.JtwigTemplate.render(JtwigTemplate.java:98)
    at org.jtwig.JtwigTemplate.render(JtwigTemplate.java:74)

I was facing a similar issue after upgrading JVM version, and I found that adding this environment variable helped:

JDK_JAVA_OPTIONS=--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED

I believe it has something to do with stricter default limits on reflection when trying to inspect built-in classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM