Open dchiaramello opened 2 years ago
Hello.
I eventually solved it by setting the Classloader when using Jinjava:
ClassLoader curClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
<Jinjava code there>
} finally {
Thread.currentThread().setContextClassLoader(curClassLoader);
}
Regards, Daniel
Should only initialization of jinjava be wrapped or in addition every call to render?
I have to do it for both the initialization and the render calls...
Few words about the case that I faced with. I have the following in code:
CompletableFuture.supplyAsync(() -> some work)
.thenAcceptAsync( a part of code that use jinjava, executor)
...
So what I observe in this case, the supply async uses fork join pool for spawning threads at executor where jinjava is used.
That means these threads will have system classloader that will not work at jinjava.
Another one point, if work submitted inside supplyAsync
completes before chain is constructed, threads at passed executor will be spawned by the main thread and in this case it will work fine.
I would not say its solved by fix provided above as usually developers doesn't track the classloaders picked. It leads to huge amount of time spent on triagging such kind of issues. It would be nice to see a fix from jinjava side.
Hello.
I am facing a weird exception (Could not find expression factory class) I don't have with Unit tests with the following template: "SVNFMGRANTID{{ vnfd_id }}{% if index is not none %}{{ index }}{% endif %}"
The Unit Test is successfully rendering the template, but when that code is in a tomee-based micro-service, it fails...
When logging the exception, I have the following TemplateError:
Corresponding Exception:
I suspect that the interesting thing may be fieldName='index is not none', I find it strange that it looks for a fieldName with that value - could it be possible that it failed to parse the template?
It may be something similar to the Filters don't seem to work issue, solved by excluding javassist and javax.el, but I don't have these dependencies in my project:
Would you have any idea/suggestion, please?
Thanks for your attention, Daniel