"BUG! exception in phase 'class generation' in source unit (...) JVM class can't be loaded for (...)"
Answered
I am trying to run my Groovy application, however this exception is thrown and my app doesn't open:
Error:Groovyc: While compiling exCircuit5: BUG! exception in phase 'class generation' in source unit 'C:\Users\[redacted]\idea-workspace\exCircuit5\src\iliquid\excircuit\gui\xml\LayoutParser.groovy' JVM class can't be loaded for iliquid.excircuit.gui.controls.container.Container
at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveJvmClass(AsmReferenceResolver.java:88)
at org.codehaus.groovy.ast.decompiled.DecompiledClassNode.getTypeClass(DecompiledClassNode.java:176)
at org.codehaus.groovy.ast.ClassNode.getTypeClass(ClassNode.java:1396)
at org.codehaus.groovy.classgen.asm.BytecodeHelper.getClassInternalName(BytecodeHelper.java:63)
at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.evaluateInstanceof(BinaryExpressionHelper.java:678)
at org.codehaus.groovy.classgen.asm.BinaryExpressionHelper.eval(BinaryExpressionHelper.java:287)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitBinaryExpression(AsmClassGenerator.java:708)
at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:60)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitBooleanExpression(AsmClassGenerator.java:835)
at org.codehaus.groovy.ast.expr.BooleanExpression.visit(BooleanExpression.java:42)
at org.codehaus.groovy.classgen.asm.StatementWriter.writeIfElse(StatementWriter.java:304)
at org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeIfElse(OptimizingStatementWriter.java:323)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitIfElse(AsmClassGenerator.java:652)
at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:43)
at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:93)
at org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeBlockStatement(OptimizingStatementWriter.java:205)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:636)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
at org.codehaus.groovy.classgen.asm.StatementWriter.writeIfElse(StatementWriter.java:310)
at org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeIfElse(OptimizingStatementWriter.java:323)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitIfElse(AsmClassGenerator.java:652)
at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:43)
at org.codehaus.groovy.classgen.asm.StatementWriter.writeBlockStatement(StatementWriter.java:93)
at org.codehaus.groovy.classgen.asm.OptimizingStatementWriter.writeBlockStatement(OptimizingStatementWriter.java:205)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:636)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:110)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:121)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:496)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:432)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:132)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:577)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1140)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:54)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:270)
at org.codehaus.groovy.control.CompilationUnit$18.call(CompilationUnit.java:850)
at org.codehaus.groovy.control.CompilationUnit$18.call(CompilationUnit.java:867)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1087)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:631)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:609)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:586)
at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:62)
at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:115)
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.jetbrains.groovy.compiler.rt.GroovycRunner.intMain2(GroovycRunner.java:134)
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.jetbrains.jps.incremental.groovy.InProcessGroovyc.runGroovycInThisProcess(InProcessGroovyc.java:158)
at org.jetbrains.jps.incremental.groovy.InProcessGroovyc.lambda$runGroovyc$0(InProcessGroovyc.java:88)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: iliquid.excircuit.ExCircuit
at org.jetbrains.groovy.compiler.rt.ClassDependencyLoader.loadClassDependencies(ClassDependencyLoader.java:106)
at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner$6.loadClassDependencies(DependentGroovycRunner.java:474)
at org.jetbrains.groovy.compiler.rt.ClassDependencyLoader.loadTypeDependencies(ClassDependencyLoader.java:40)
at org.jetbrains.groovy.compiler.rt.ClassDependencyLoader.loadClassDependencies(ClassDependencyLoader.java:84)
at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner$6.loadClassDependencies(DependentGroovycRunner.java:474)
at org.jetbrains.groovy.compiler.rt.ClassDependencyLoader.loadDependencies(ClassDependencyLoader.java:34)
at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner$7$1.loadClass(DependentGroovycRunner.java:493)
at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveJvmClass(AsmReferenceResolver.java:86)
... 57 more
As far as I know, this only occurs in IntelliJ IDEA, but it doesn't occur in my Ant build. That's why I asked the question here.
I am using the latest version of Groovy (3.0.0-alpha-3).
Please sign in to leave a comment.
Please report at https://youtrack.jetbrains.com/issues/IDEA with the sample to reproduce attached. Double check the classpath, Groovy and JDK versions are exactly the same in the command line Ant and in IntelliJ IDEA project.
@Serge Baranov It seems like this issue happens very inconsistently. Out of frustration I decided to remove and re-add Groovy to my project and the issue has disappeared.
Regarding Ant, I only have one Groovy version installed on my computer (3.0.0-alpha-3), so both IntelliJ IDEA and Ant are using the same version.
Anyway, I hope this was a one time thing. If this issue occurs again, I'll be sure to submit it to YouTrack.
Thank you.
Got the same problem on my machine.
After some digging I realised that the problem was caused by a mismatch in Groovy versions.
Maven was using Groovy 2.5.7, which understands traits. While the "Global Libraries" in IntelliJ were still pointing to Groovy-2.4.6, which didn't know traits.
After removing the old global library in IntelliJ and replacing it with the 2.5.7 version of Groovy, the problem was resolved.
We recently updated our usage from Groovy 2.4.15 to 2.5.4 and, for the most part, everything went well. However, as I came back from some time off for the holidays, I started seeing this same "bug." It was completely random (even the class it couldn't find would change) and sometimes just checking out a different branch from version control would fix it. But then this morning, nothing would fix it, so I reverted to searching the internet for a solution/explanation.
Having already run across this post, I'd already checked for mismatches, etc. However, with the way we're setup, we don't need Groovy in "Global Libraries." And as I said, the issue was random. Last night, the app would build and run just fine. This morning, I got the error. Literally, nothing had changed besides a TODO. Turns out all of my coworkers had already crossed this issue since they'd done more work since the upgrade. The solution was simply to do a Build > Rebuild Project. The clue is was that doing a " clean build" with Gradle would always work, so it was the internal IntelliJ build that was failing.
This error would occur randomly while I was working on gradle-based Spring Boot projects. This is without changing between versions of Groovy, or anything else like that. I could be working all day without a problem, and then out of nowhere this error would occur. The following would work for me:
I tried deleting the .gradle folder as suggested elsewhere, and that never worked for me, nor did invalidating the caches and restarting IDEA.
This error happened today while using version 2019.3.4.
Alternatively, run Invalidate Caches and Restart from File menu.
I failed to mention that I was previously using 2019.1.4. However, this is still an issue on 2020.1.4 (we can't use anything newer because a required plugin is not yet compatible).
Sorry for the problem, any steps to reproduce would be appreciated. We still recommend using YouTrack instead of this forum for reporting such issues: https://youtrack.jetbrains.com/newIssue?project=IDEA . Thank you.