Spock: Stack size too large when running tests in Idea

Created on 9 Mar 2015  路  10Comments  路  Source: spockframework/spock

To reproduce:

You'll receive

Exception in thread "main" java.lang.VerifyError: (class: com/example/ASpec, method: $spock_feature_0_0 signature: ()V) Stack size too large
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2499)
    at java.lang.Class.getDeclaredFields(Class.java:1811)
    at org.spockframework.runtime.SpecInfoBuilder.buildFields(SpecInfoBuilder.java:98)
    at org.spockframework.runtime.SpecInfoBuilder.doBuild(SpecInfoBuilder.java:69)
    at org.spockframework.runtime.SpecInfoBuilder.build(SpecInfoBuilder.java:54)
    at org.spockframework.runtime.Sputnik.getSpec(Sputnik.java:80)
    at org.spockframework.runtime.Sputnik.runExtensionsIfNecessary(Sputnik.java:88)
    at org.spockframework.runtime.Sputnik.getDescription(Sputnik.java:55)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:43)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Note that

  • in console everything works fine (gradle build passes)
  • the test cannot be run even if the test method is annotated with @Ignore
  • if you extract variable (uncomment lines 14-15), the bug disappears (!)
  • if you remove the 2nd argument of anAbc(), the bug disappears

I believe this is a Spock bug, as Idea calls a public Spock method.

Environment

  • Idea 14.0.3 build 139.1117
  • JRE 1.8.0_31, also can be reproduced on 1.7.0_76-b13
  • Spock 1.0-groovy-2.4, but the same happened on 0.7-groovy-2.0
  • Ubuntu 14.10 x86_64
not a bug

All 10 comments

I could reproduce the results on win7 64, but I suspect the IntelliJ compiler. It produced different bytecode as the one produced by gradle and when you enable invoke dynamic support for the groovy compiler in the Intellij settings the error disappears.
I would say it is not necessarily a spock issue but more a groovy-Intellij issue.

IntelliJ teams says they will improve Groovy compilation in the upcoming version 4.1, but I haven't tried it yet: http://blog.jetbrains.com/idea/2015/03/faster-groovy-compilation-in-intellij-idea-14-1/

Since that feature uses a different compiler I would wager that it works also.

I could reproduce the bug using both idea-IU-141.176.5 and the recently released idea-IU-141.177.4 (official 14.1) releases.

 /usr/lib/jvm/oracle-jdk-bin-1.8/bin/java -ea -Didea.launcher.port=7534 -Didea.launcher.bin.path=/opt/idea-IU-141.177.4/bin -Dfile.encoding=UTF-8 -classpath /opt/idea-IU-141.177.4/lib/idea_rt.jar:/opt/idea-IU-141.177.4/plugins/junit/lib/junit-rt.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/jfxswt.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/jce.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/jsse.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/resources.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/rt.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/charsets.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/plugin.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/javaws.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/management-agent.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/deploy.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/jfr.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/localedata.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/zipfs.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/nashorn.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/jfxrt.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/cldrdata.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/dnsns.jar:/usr/lib/jvm/oracle-jdk-bin-1.8/jre/lib/ext/sunec.jar:/home/gus/workspace/spock/issues/spock-stack-bug/build/classes/test:/home/gus/workspace/spock/issues/spock-stack-bug/build/classes/main:/home/gus/workspace/spock/issues/spock-stack-bug/build/resources/test:/home/gus/workspace/spock/issues/spock-stack-bug/build/resources/main:/home/gus/.gradle/caches/modules-2/files-2.1/org.spockframework/spock-core/1.0-groovy-2.4/ceaa8b69f274ed3de24da3e6a6c86f673b426d1a/spock-core-1.0-groovy-2.4.jar:/home/gus/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.4.1/a9ca9c9de09361ec2a18d2c058d2524fbd8eae0c/groovy-all-2.4.1.jar:/home/gus/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar:/home/gus/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.example.ASpec

Produces the stacktrace below:

Exception in thread "main" java.lang.VerifyError: (class: com/example/ASpec, method: $spock_feature_0_0 signature: ()V) Stack size too large
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.spockframework.runtime.SpecInfoBuilder.buildFields(SpecInfoBuilder.java:98)
at org.spockframework.runtime.SpecInfoBuilder.doBuild(SpecInfoBuilder.java:69)
at org.spockframework.runtime.SpecInfoBuilder.build(SpecInfoBuilder.java:54)
at org.spockframework.runtime.Sputnik.getSpec(Sputnik.java:80)
at org.spockframework.runtime.Sputnik.runExtensionsIfNecessary(Sputnik.java:88)
at org.spockframework.runtime.Sputnik.getDescription(Sputnik.java:55)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:43)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

More interestingly, I could get the 'throws' test to run inside Intellij by selecting test method specifically (rather than the spec). After that it is then possible to get the IDE to run ASpec successfully. Selecting Build -> Rebuild Project puts it back into its initial broken state.

As it runs successfully under Gradle / outside Intellij I don't think this is a spock issue. Have you raised an equivalent issue over at Intellij?

I've rerun the tests and it seems to be fixed in Intellij 14.1.4
Can you verify this @Derbeth @guspower

The same in Intellij 15.0.4

I just hit this with a test from our own test suite using spock-1.0-groovy-2.4, groovy-2.4.4 and IntelliJ 2016.1.3 Build #IU-145.1617.

Any updates on that? Here's code the snipped to reproduce it:
https://gist.github.com/Pyrolistical/8741574

For some reason, if you wrap 'helperMethod' in a private class, it works.

I can reproduce this error outside of IntelliJ

  1. Add to build.gradle
sourceCompatibility = 1.5
targetCompatibility = 1.5
  1. Run gradle clean test
  2. Observe the report:
java.lang.VerifyError: (class: com/example/ASpec, method: $spock_feature_0_0 signature: ()V) Stack size too large
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.spockframework.runtime.SpecInfoBuilder.buildFields(SpecInfoBuilder.java:98)
    at org.spockframework.runtime.SpecInfoBuilder.doBuild(SpecInfoBuilder.java:69)
    at org.spockframework.runtime.SpecInfoBuilder.build(SpecInfoBuilder.java:54)
    at org.spockframework.runtime.Sputnik.getSpec(Sputnik.java:80)
    at org.spockframework.runtime.Sputnik.runExtensionsIfNecessary(Sputnik.java:88)
    at org.spockframework.runtime.Sputnik.run(Sputnik.java:61)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:116)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:59)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
    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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

wites342 picture wites342  路  4Comments

ahlinist picture ahlinist  路  7Comments

minjing picture minjing  路  4Comments

kriegaex picture kriegaex  路  5Comments

chrylis picture chrylis  路  9Comments