Closed lglauer closed 2 years ago
we have run into a similar issue. in our case janino, commons-compiler and commons-compiler-jdk are all on the classpath. compilation fail when importing a class from a dependency.
the exact same code runs as is with 3.1.6. the only change being the dependency bump to 3.1.7.
it should be noted that the problem only manifest itself when using the jdk compiler (org.codehaus.commons.compiler.jdk.CompilerFactory). the janino compiler (org.codehaus.janino.CompilerFactory) works just fine.
@aunkrig Any comment? Is janino
still actively maintained? This is a serious regression and should be fixed ASAP.
I'll look into it soon.
The answer is very simple: Both "commons-compiler-jdk" and "janino" say "class javax.annotation.Nonnull not found" because -- that class cannot be found! The reason being is that the annotation interface "javax.annotation.Nonnull" is not part of the JRE (tested with 8, 11 and 17), so one needs an extra library that supplies this annotation interface. If found the following libs:
com.google.code.findbugs:jsr305-3.0.2
org.apache.tools.ant:annotations-2.0.1
In other words: When you switched from 3.1.6 to 3.1.7, you must have accidentially removed that library from the classpath!
@aunkrig Did you have a look at the minimal reproducible example? It has a dependency to com.google.code.findbugs:jsr305
(see here). And as I said it works with commons-compiler-jdk:3.16
and fails with commons-compiler-jdk:3.17
, no other difference.
Oops, I missed that dependency when I ran the sample program. Now I can reproduce the problem... stay tuned.
I think I fixed it (JavaFileManagers.java:120)... please test!
I also added a regression test case "testIssue168()" that verifies the absence of the bug.
Thank you! I will test it in the next days.
@aunkrig the fix is working for my test case. can you also please include PR #170 ?
Yes, that solution seems to work! Thanks 👍
My pleasure! Thank you for the very useful test case. I added a regression test case org.codehaus.commons.compiler.tests.ReportedBugsTest.testIssue168()
that verifies this fix.
Hello!
When only
commons-compiler-jdk
is on the classpath, but notjanino
theSimpleCompiler
class fromcommons-compiler-jdk
is used. Since release 3.17 it fails to load the annotation classjavax.annotation.Nonnull
from the classpath. Prior this scenario worked fine, so it seems to be a regression. I created a minimal reproducible example for this case: https://github.com/lglauer/janino-testWhen executed it prints the following exception:
If
janino
is added as a dependency or ifcommons-compiler-jdk
3.16 is used the example code works fine and prints "Hello World!".Thanks in advance!