Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 2.5.12
-
Fix Version/s: 2.5.13
-
Component/s: None
-
Labels:None
-
Environment:Mac OS
-
Testcase included:yes
-
Number of attachments :
Description
As far as I could tell, the bug only shows itself when a similarly named static variable appears in two classes in two different packages with different visibility (public/private). I've zipped a minimal pair of packages that demonstrates the problem.
Steps to reproduce:
1. Unzip the attatched directory.
2. Compile class b.C3 using something like:
-----------
import java.io.File;
import org.codehaus.janino.JavaSourceClassLoader;
import org.codehaus.janino.DebuggingInformation;
public class Test1 {
public static void main(String[] args) throws Exception {
ClassLoader loader = new JavaSourceClassLoader(
Test1.class.getClassLoader(),
new File[]{new File("testsrc")},
null, DebuggingInformation.NONE);
loader.loadClass("b.C3");
}
}
---------------
Above throws following NPE:
Exception in thread "main" java.lang.NullPointerException
at org.codehaus.janino.UnitCompiler.checkAccessible(UnitCompiler.java:4258)
at org.codehaus.janino.UnitCompiler.checkAccessible(UnitCompiler.java:4235)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:2315)
at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:51)
at org.codehaus.janino.UnitCompiler$9.visitFieldAccess(UnitCompiler.java:2283)
at org.codehaus.janino.Java$FieldAccess.accept(Java.java:2006)
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2290)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:2309)
at org.codehaus.janino.UnitCompiler.access$6100(UnitCompiler.java:51)
at org.codehaus.janino.UnitCompiler$9.visitAmbiguousName(UnitCompiler.java:2281)
at org.codehaus.janino.Java$AmbiguousName.accept(Java.java:1942)
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2290)
at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3231)
at org.codehaus.janino.UnitCompiler.compileArithmeticOperation(UnitCompiler.java:4574)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:2791)
at org.codehaus.janino.UnitCompiler.access$4400(UnitCompiler.java:51)
at org.codehaus.janino.UnitCompiler$9.visitBinaryOperation(UnitCompiler.java:2263)
at org.codehaus.janino.Java$BinaryOperation.accept(Java.java:2400)
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2290)
at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3231)
at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:2870)
at org.codehaus.janino.UnitCompiler.access$5100(UnitCompiler.java:51)
at org.codehaus.janino.UnitCompiler$9.visitMethodInvocation(UnitCompiler.java:2270)
at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2530)
at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2290)
at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3231)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1777)
at org.codehaus.janino.UnitCompiler.access$2500(UnitCompiler.java:51)
at org.codehaus.janino.UnitCompiler$6.visitMethodInvocation(UnitCompiler.java:1751)
at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2530)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1771)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1070)
at org.codehaus.janino.UnitCompiler.access$800(UnitCompiler.java:51)
at org.codehaus.janino.UnitCompiler$4.visitExpressionStatement(UnitCompiler.java:625)
at org.codehaus.janino.Java$ExpressionStatement.accept(Java.java:1277)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:644)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:663)
at org.codehaus.janino.UnitCompiler.access$700(UnitCompiler.java:51)
at org.codehaus.janino.UnitCompiler$4.visitBlock(UnitCompiler.java:624)
at org.codehaus.janino.Java$Block.accept(Java.java:1231)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:644)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1662)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:375)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:261)
at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:234)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:674)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:240)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:218)
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:333)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:293)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at Test1.main(Test1.java:14)
Process finished with exit code 1
I probably should have used a higher priorty when reporting this since it turned out to be a showstopper for us. We subsequently found some more bugs - all of which seem to point to problems in the way that Janino does name resolution across multiple files. For now we have cut over to the 1.6 compiler API but we would like to use Janino so we can deploy to JREs - so would be interested in any comments you have. If you'd like to contact me directly I'm at philip<at>pmilne<dot>net.