Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation failure when a class and package name match case insensitively #165

Closed
shardulm94 opened this issue Mar 22, 2022 · 3 comments
Closed

Comments

@shardulm94
Copy link

shardulm94 commented Mar 22, 2022

Suppose we have a class com.company.User and another class com.company.user.Country. If we now try to compile a class which references Country using ClassBodyEvaluator, the compilation fails with the error mentioned below. I have created shardulm94@acb88d7 which reproduces the issue. Based on my understanding, this may be a bug in the implementation for JLS 6.5.2.2 where Janino tries to disambiguate names, where UnitCompiler.java#L8761 fails instead of probably returning null when the class is not present, but a package with the same name (different if you compare case sensitively) is present.

java.lang.NoClassDefFoundError: com/company/user (wrong name: com/company/User)

	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.codehaus.janino.ClassLoaderIClassLoader.findIClass(ClassLoaderIClassLoader.java:75)
	at org.codehaus.janino.IClassLoader.loadIClass(IClassLoader.java:319)
	at org.codehaus.janino.UnitCompiler.findTypeByName(UnitCompiler.java:8840)
	at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java:8761)
	at org.codehaus.janino.UnitCompiler.reclassifyName(UnitCompiler.java:8754)
	at org.codehaus.janino.UnitCompiler.reclassify(UnitCompiler.java:8612)
	at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:7134)
	at org.codehaus.janino.UnitCompiler.access$17900(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$24.visitAmbiguousName(UnitCompiler.java:6725)
	at org.codehaus.janino.UnitCompiler$24.visitAmbiguousName(UnitCompiler.java:6722)
	at org.codehaus.janino.Java$AmbiguousName.accept(Java.java:4592)
	at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:6722)
	at org.codehaus.janino.UnitCompiler.access$14900(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$23.visitLvalue(UnitCompiler.java:6682)
	at org.codehaus.janino.UnitCompiler$23.visitLvalue(UnitCompiler.java:6679)
	at org.codehaus.janino.Java$Lvalue.accept(Java.java:4517)
	at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:6679)
	at org.codehaus.janino.UnitCompiler.access$14200(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$21.visitRvalue(UnitCompiler.java:6625)
	at org.codehaus.janino.UnitCompiler$21.visitRvalue(UnitCompiler.java:6616)
	at org.codehaus.janino.Java$Rvalue.accept(Java.java:4487)
	at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:6616)
	at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:9337)
	at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:5172)
	at org.codehaus.janino.UnitCompiler.access$9200(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$15.visitMethodInvocation(UnitCompiler.java:4674)
	at org.codehaus.janino.UnitCompiler$15.visitMethodInvocation(UnitCompiler.java:4647)
	at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:5459)
	at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:4647)
	at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:5817)
	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2748)
	at org.codehaus.janino.UnitCompiler.access$2800(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1552)
	at org.codehaus.janino.UnitCompiler$6.visitReturnStatement(UnitCompiler.java:1535)
	at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:3887)
	at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1535)
	at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1619)
	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:3574)
	at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3249)
	at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1391)
	at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1364)
	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:808)
	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:985)
	at org.codehaus.janino.UnitCompiler.access$700(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$2.visitMemberClassDeclaration(UnitCompiler.java:402)
	at org.codehaus.janino.UnitCompiler$2.visitMemberClassDeclaration(UnitCompiler.java:394)
	at org.codehaus.janino.Java$MemberClassDeclaration.accept(Java.java:1532)
	at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:394)
	at org.codehaus.janino.UnitCompiler.compileDeclaredMemberTypes(UnitCompiler.java:1341)
	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:843)
	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:420)
	at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:399)
	at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:394)
	at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1687)
	at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:394)
	at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:367)
	at org.codehaus.janino.UnitCompiler.access$000(UnitCompiler.java:236)
	at org.codehaus.janino.UnitCompiler$1.visitCompilationUnit(UnitCompiler.java:341)
	at org.codehaus.janino.UnitCompiler$1.visitCompilationUnit(UnitCompiler.java:338)
	at org.codehaus.janino.Java$CompilationUnit.accept(Java.java:370)
	at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:338)
	at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:254)
	at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:294)
	at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:288)
	at org.codehaus.janino.ClassBodyEvaluator.cook(ClassBodyEvaluator.java:267)
	at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:82)
	at org.codehaus.janino.tests.Repro.test(Repro.java:19)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
aunkrig added a commit that referenced this issue Mar 28, 2022
@aunkrig
Copy link
Member

aunkrig commented Mar 28, 2022

Hey Shardul,

thank you for your very precise bug report! I believe I fixed it... please test.

The same problem may arise, even worse, when two classes exist in different packages, and their simple names differ only in case. E.g. a.BreakPoint and b.Breakpoint, and you import both, and then use any of the two.

CU Arno

aunkrig added a commit that referenced this issue Mar 28, 2022
@shardulm94
Copy link
Author

Thanks @aunkrig. I tested the change in my application where I encountered the issue originally and it works!

@aunkrig
Copy link
Member

aunkrig commented Mar 28, 2022

Bingo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants