Skip to content

Not fail with NullPointerException on trying to run Spock with unsupported Groovy version in IDEA #1421

@szpak

Description

@szpak

Is your feature request related to a problem?

Currently, a build (compilation) with incompatible Spock and Groovy version fails in IDEA 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

It holds also with spock-2.0-groovy-2.5 and Groovy 3.0. The problem is no location returned for CodeSource in:

public class GroovyReleaseInfo {
public static VersionNumber getVersion() {
return VersionNumber.parse(ReleaseInfo.getVersion());
}
public static String getArtifactPath() {
return GroovyObject.class.getProtectionDomain().getCodeSource().getLocation().toString();
}

Describe the solution you'd like

Some of:

  1. Explain why Idea do that and report a bug.
  2. Find a "better" way to get JAR location.
  3. Be more resilient to the unexpected exceptions to show the intended error message about incompatibilities (even in a reduced form) instead of NPE.

Describe alternatives you've considered

No response

Additional context

The problem seems to occur only in IDEA with Maven projects and Gradle projects with "build and run" switched to Idea (instead of Gradle).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions