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

NullPointerException while compiling Spock 2.0-groovy-3.0 with Groovy 4.0.0 in IDEA #1420

Closed
szpak opened this issue Jan 29, 2022 · 1 comment
Labels

Comments

@szpak
Copy link
Member

szpak commented Jan 29, 2022

Describe the bug

It is problematic to compile project with Spock 2.0-groovy-3.0 and Groovy 4.0.0 in IDEA when compilation is done by IDEA (in a Maven project or a Gradle project with "build and run" switched to Idea (instead of Gradle).

To Reproduce

Download a sample Spock 2.0 + Groovy 4.0 project (from my blog post):
https://github.com/szpak/code-examples-and-poc/tree/master/spock2-groovy4-gradle-maven

and import it in IDEA (tested with 2021.2.3) as a Maven.
(or as a Gradle project with changed "Build and run" from "Gradle" to "IntelliJ IDEA" in File | Settings | Build, Execution, Deployment | Build Tools | Gradle).

Try to build (CTRL-F9).

Expected behavior

Project compiles fine (or at least an error about incompatible Spock and Groovy version is emitted, which is possible to override with -Dspock.iKnowWhatImDoing.disableGroovyVersionCheck).

Actual behavior

Build (compilation) fails with:

Groovyc: While compiling [tests of spock2-groovy4-gradle.test]: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/foobar/.m2/repository/org/spockframework/spock-core/2.0-groovy-3.0/spock-core-2.0-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation  because of exception java.lang.NullPointerException

With a newer Java version the exception (NPE) is more verbose:

Groovyc: While compiling [tests of spock2-groovy4-gradle.test]: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at jar:file:/home/foobar/.m2/repository/org/spockframework/spock-core/2.0-groovy-3.0/spock-core-2.0-groovy-3.0.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation  because of exception java.lang.NullPointerException: Cannot invoke "java.net.URL.toString()" because the return value of "java.security.CodeSource.getLocation()" is null

Java version

Tested with 11, 15, 17.

Buildtool version

Gradle 7.3, Idea 2021.2.3.

What operating system are you using

Linux

Dependencies

spock-2.0-groovy-3.0
groovy-4.0.0

Additional context

I'm not sure where the problem is located, because the compilation:

  • works with Groovy 3.x (also in Idea) - problem with Groovy 4?
  • works with Gradle (natively and when Gradle build project inside Idea) - problem with IDEA?
  • works with Maven (natively) - problem with IDEA?

Spock uses that method as follow:

public class GroovyReleaseInfo {
  public static VersionNumber getVersion() {
    return VersionNumber.parse(ReleaseInfo.getVersion());
  }

  public static String getArtifactPath() {
    return GroovyObject.class.getProtectionDomain().getCodeSource().getLocation().toString();
  }
}

The IDEA could be problematic to return null as location, but it works fine with Groovy 3... Any hints?

@szpak szpak added the bug label Jan 29, 2022
@szpak
Copy link
Member Author

szpak commented Jan 29, 2022

Having that bug ready to send I closed down the problem to IDEA and reported #1421 instead.

I reported also that (already written down) one for reference for people looking for the similar problems.

@szpak szpak closed this as completed Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant