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

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

Closed
szpak opened this issue Jan 29, 2022 · 4 comments

Comments

@szpak
Copy link
Member

szpak commented Jan 29, 2022

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).

@szpak
Copy link
Member Author

szpak commented Jan 29, 2022

I reported the problem in IDEA:
https://youtrack.jetbrains.com/issue/IDEA-287643

And also a related limitation - unable to pass system properties to groovyc:
https://youtrack.jetbrains.com/issue/IDEA-287642
(and a feature request in Groovy itself to mitigate limitations in Idea - https://issues.apache.org/jira/browse/GROOVY-10468)

@leonard84
Copy link
Member

@szpak is there something that Spock can do, it sounds like an intellij problem?

@szpak
Copy link
Member Author

szpak commented Feb 7, 2022

It is an Idea problem, but we would catch handle exceptions and display a regular error message just with "unknown path" for the artifacts (point 3).

@leonard84
Copy link
Member

I added some basic resiliency in b218847

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants