I opened the Spock project in a freshly installed ...
# groovy
v
I opened the Spock project in a freshly installed Eclipse with a freshly installed greclipse. I found this in the Eclipse log, how can this happen?
Copy code
ava.lang.NoSuchMethodError: 'org.codehaus.groovy.ast.stmt.TryCatchStatement org.codehaus.groovy.ast.stmt.TryCatchStatement.addCatch(org.codehaus.groovy.ast.stmt.CatchStatement)'
	at org.spockframework.compiler.ConditionRewriter.surroundWithTryCatch(ConditionRewriter.java:796)
	at org.spockframework.compiler.ConditionRewriter.rewriteOtherCondition(ConditionRewriter.java:739)
	at org.spockframework.compiler.ConditionRewriter.rewriteCondition(ConditionRewriter.java:654)
	at org.spockframework.compiler.ConditionRewriter.rewriteCondition(ConditionRewriter.java:626)
	at org.spockframework.compiler.ConditionRewriter.rewriteImplicitCondition(ConditionRewriter.java:102)
	at org.spockframework.compiler.DeepBlockRewriter.handleImplicitCondition(DeepBlockRewriter.java:234)
	at org.spockframework.compiler.DeepBlockRewriter.doVisitExpressionStatement(DeepBlockRewriter.java:89)
	at org.spockframework.compiler.AbstractDeepBlockRewriter.visitExpressionStatement(AbstractDeepBlockRewriter.java:105)
	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:41)
	at org.spockframework.compiler.StatementReplacingVisitorSupport.replace(StatementReplacingVisitorSupport.java:44)
	at org.spockframework.compiler.AbstractDeepBlockRewriter.visit(AbstractDeepBlockRewriter.java:89)
	at org.spockframework.compiler.DeepBlockRewriter.visit(DeepBlockRewriter.java:60)
	at org.spockframework.compiler.SpecRewriter.visitAnyBlock(SpecRewriter.java:485)
	at org.spockframework.compiler.model.ExpectBlock.accept(ExpectBlock.java:31)
	at org.spockframework.compiler.model.Method.accept(Method.java:70)
	at org.spockframework.compiler.model.Spec.accept(Spec.java:112)
	at org.spockframework.compiler.SpockTransform$Impl.processSpec(SpockTransform.java:73)
	at org.spockframework.compiler.SpockTransform$Impl.visit(SpockTransform.java:62)
	at org.spockframework.compiler.SpockTransform.visit(SpockTransform.java:48)
	at org.codehaus.groovy.transform.ASTTransformationVisitor.lambda$5(ASTTransformationVisitor.java:453)
	at org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:939)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:678)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:652)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.processToPhase(GroovyCompilationUnitDeclaration.java:243)
	at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.resolve(GroovyCompilationUnitDeclaration.java:639)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:833)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.processing(ProcessTaskManager.java:135)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:328)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
	at java.base/java.lang.Thread.run(Thread.java:1474)
I'm debugging Eclipse right now and sitting at a breakpoint where it happened. Both instances come from the same class loader. Also, doing
tryCatchStatement.addCatch(catchStatement)
in the debugger evaluation works just fine without exception. But the breakpoint is in the constructor of the
NoSuchMethodError
, so it just happened at that exact place. 😕 It even happens consistently and reproducibly. If I recompile
GuiceMultiModules
when it tries to transform the
assert service1 instanceof IService1
. Or also any of the other 5 explicit and implicit assertions. Even if I have only one
expect: true
it happens. Even if I boil down the whole class to just
Copy code
package org.spockframework.guice

import spock.lang.Specification

class Foo extends Specification {
  def foo() {
    expect: true
  }
}
I even took out the debugger evaluation out of the loop, writing those 5 expressions to a text-file and when the breakpoint in the exception hit looked at the text file, still the classloader is the same.
✅ 1
b
That should have worked indeed. The only remaining possibility I can imagine is that the written bytecode is not actually calling addCatch(CaseStatement). What else it is supposed to call instead I have no clue about though.
v
Thanks, should have mentioned, that I also opened an issue about it at github.com/groovy/groovy-eclipse/issues/1697. Forgot that the return type is part of binary compatibility, so there was most probably some problem with Groovy 4 vs. Groovy 5 where the return type of that method changed from
void
to
TryCatchStatement
and a bridge method was missing in greclipse but is fixed now.