PebbleTemplates / pebble

Java Template Engine
https://pebbletemplates.io
BSD 3-Clause "New" or "Revised" License
1.1k stars 168 forks source link

No support for native-image with GraalVM #647

Closed noblehelm closed 1 year ago

noblehelm commented 1 year ago

When trying to run a SpringBoot project with Template files in PebbleTemplates in Native Image mode, an error is thrown for a specific expression not evaluated due to missing constructors for the operations:

Servlet.service() for servlet [dispatcherServlet] in context with path [/api/planrepository] threw exception [Request processing failed: java.lang.RuntimeException: java.lang.InstantiationException: io.pebbletemplates.pebble.node.expression.UnaryNotExpression] with root cause

java.lang.NoSuchMethodException: io.pebbletemplates.pebble.node.expression.UnaryNotExpression.<init>()
    at java.base@17.0.5/java.lang.Class.getConstructor0(DynamicHub.java:3585) ~[native:na]
    at java.base@17.0.5/java.lang.Class.newInstance(DynamicHub.java:626) ~[native:na]
    at io.pebbletemplates.pebble.parser.ExpressionParser.parseExpression(ExpressionParser.java:120) ~[na:na]
    at io.pebbletemplates.pebble.parser.ExpressionParser.parseExpression(ExpressionParser.java:92) ~[na:na]
    at io.pebbletemplates.pebble.parser.ExpressionParser.parseExpression(ExpressionParser.java:132) ~[na:na]
    at io.pebbletemplates.pebble.parser.ExpressionParser.parseExpression(ExpressionParser.java:193) ~[na:na]
    at io.pebbletemplates.pebble.parser.ExpressionParser.parseExpression(ExpressionParser.java:92) ~[na:na]
    at io.pebbletemplates.pebble.parser.ExpressionParser.parseExpression(ExpressionParser.java:132) ~[na:na]
    at io.pebbletemplates.pebble.parser.ExpressionParser.parseExpression(ExpressionParser.java:92) ~[na:na]
    at io.pebbletemplates.pebble.tokenParser.IfTokenParser.parse(IfTokenParser.java:37) ~[na:na]
    at io.pebbletemplates.pebble.parser.ParserImpl.subparse(ParserImpl.java:196) ~[na:na]
    at io.pebbletemplates.pebble.parser.ParserImpl.subparse(ParserImpl.java:105) ~[na:na]
    at io.pebbletemplates.pebble.parser.ParserImpl.parse(ParserImpl.java:98) ~[na:na]
    at io.pebbletemplates.pebble.PebbleEngine.getPebbleTemplate(PebbleEngine.java:170) ~[native:na]
    at io.pebbletemplates.pebble.PebbleEngine.lambda$getTemplate$0(PebbleEngine.java:152) ~[native:na]
    at java.base@17.0.5/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[native:na]
    at io.pebbletemplates.pebble.cache.template.ConcurrentMapTemplateCache.computeIfAbsent(ConcurrentMapTemplateCache.java:25) ~[na:na]
    at io.pebbletemplates.pebble.cache.template.ConcurrentMapTemplateCache.computeIfAbsent(ConcurrentMapTemplateCache.java:10) ~[na:na]
    at io.pebbletemplates.pebble.PebbleEngine.getTemplate(PebbleEngine.java:152) ~[native:na]
    at io.pebbletemplates.pebble.PebbleEngine.getTemplate(PebbleEngine.java:123) ~[native:na]

This error was thrown for the UnaryNot operation, but it might be happening for every other operation that is evaluated for the templates themselves.

Is there any support for the native-image for the Pebble templates library? Could we open a PR for the inclusion of TypeHints?

ebussieres commented 1 year ago

Fixed in release 3.2.1