File tree Expand file tree Collapse file tree 2 files changed +44
-4
lines changed
spock-core/src/main/java/org/spockframework/compiler
spock-specs/src/test/groovy/org/spockframework/smoke Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -266,11 +266,17 @@ private static boolean checkIsConditionBlock(MethodCallExpression methodCallExpr
266266 ClassNode targetType = methodCallExpr .getObjectExpression ().getType ();
267267 String methodName = methodCallExpr .getMethodAsString ();
268268
269- List <MethodNode > methods = targetType .getMethods (methodName );
270- for (MethodNode method : methods ) {
271- for (AnnotationNode annotation : method .getAnnotations ()) {
272- if (annotation .getClassNode ().getName ().equals (ConditionBlock .class .getName ())) return true ;
269+ try {
270+ // if targetType has any method with a parameter or return type that is not in the
271+ // compile classpath this call will fail with a NoClassDefFoundError
272+ List <MethodNode > methods = targetType .getMethods (methodName );
273+ for (MethodNode method : methods ) {
274+ for (AnnotationNode annotation : method .getAnnotations ()) {
275+ if (annotation .getClassNode ().getName ().equals (ConditionBlock .class .getName ())) return true ;
276+ }
273277 }
278+ } catch (NoClassDefFoundError e ) {
279+ // just assume there is no condition block and return false
274280 }
275281
276282 return false ;
Original file line number Diff line number Diff line change 1414
1515package org.spockframework.smoke
1616
17+ import org.codehaus.groovy.ast.ClassNode
18+ import org.jetbrains.annotations.Debug
1719import org.spockframework.EmbeddedSpecification
1820import org.spockframework.compiler.InvalidSpecCompileException
1921
@@ -80,4 +82,36 @@ println "hi"
8082 then :
8183 thrown(InvalidSpecCompileException )
8284 }
85+
86+ static class Foo {
87+ Debug getDebug () { return null }
88+ void bar () {}
89+ }
90+
91+ def " compiling with missing dependencies does not fail" () {
92+ given :
93+ compiler. addClassImport(' org.spockframework.smoke.CompileTimeErrorReporting.Foo' )
94+
95+ when :
96+ new ClassNode (Class . forName(' org.spockframework.smoke.CompileTimeErrorReporting$Foo' ))
97+ .getMethods(' bar' )
98+
99+ then : ' make sure it would fail for the right reason, this might change if `Debug` makes it into the runtime classpath'
100+ NoClassDefFoundError ncdfe = thrown()
101+ println (ncdfe. message)
102+ ncdfe. message. contains(' org.spockframework.smoke.CompileTimeErrorReporting$Foo' )
103+ ncdfe. message. contains(' org/jetbrains/annotations/Debug' )
104+
105+ when :
106+ compiler. compileFeatureBody """
107+ when:
108+ new Foo().bar()
109+
110+ then:
111+ noExceptionThrown()
112+ """
113+
114+ then :
115+ noExceptionThrown()
116+ }
83117}
You can’t perform that action at this time.
0 commit comments