0

I have been struggling to understand why groovyc does not want to compile my code for awhile and I finally narrowed it down to it disliking the dependency JSR308 Type Annotations Compiler, which uses as one of its package names java.lang.annotations.

When groovyc tries to compile my code with this jar in its classpath, the following is printed:

groovyc -cp jsr308-compiler-1.7.5.jar EmptyClass.groovy 
>>> a serious error occurred: null
>>> stacktrace:
java.lang.ExceptionInInitializerError
    at org.codehaus.groovy.classgen.Verifier.<clinit>(Verifier.java:137)
    at org.codehaus.groovy.control.CompilationUnit.<init>(CompilationUnit.java:171)
    at org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit.<init>(JavaAwareCompilationUnit.java:66)
    at org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit.<init>(JavaAwareCompilationUnit.java:57)
    at org.codehaus.groovy.tools.FileSystemCompiler.<init>(FileSystemCompiler.java:64)
    at org.codehaus.groovy.tools.FileSystemCompiler.doCompilation(FileSystemCompiler.java:224)
    at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompile(FileSystemCompiler.java:163)
    at org.codehaus.groovy.tools.FileSystemCompiler.commandLineCompileWithErrorHandling(FileSystemCompiler.java:203)
    at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:187)
    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.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:110)
    at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
Caused by: java.lang.SecurityException: Prohibited package name: java.lang.annotation
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:662)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:761)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at org.codehaus.groovy.tools.RootLoader.oldFindClass(RootLoader.java:174)
    at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:146)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.codehaus.groovy.ast.ClassHelper.<clinit>(ClassHelper.java:129)
    ... 15 more

Running javac -cp jsr308-compiler-1.7.5.jar EmptyClass.java successfully compiles the dummy class.

java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~16.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
groovy -version
Groovy Version: 3.0.0-beta-2 JVM: 1.8.0_222 Vendor: Private Build OS: Linux

From what I have read, the Type Annotations Project was integrated into JDK 8 back in 2014, so I have no idea why groovyc would not recognize this dependency's right to use java.lang.annotation as a package name.

[Update] As requested, here is the code for both EmptyClass.groovy and EmptyClass.java:

public class EmptyClass {

}
  • You neglected to include your class. Additionally, be careful about Groovy 3; although they're intending to target Java 8, it's really a Java 9 native (because of the overhaul required to work under Jigsaw), and I would not be shocked to see problems. – chrylis -cautiouslyoptimistic- Jul 31 '19 at 18:38
  • http://groovy-lang.org/releasenotes/groovy-3.0.html#Groovy3.0releasenotes-Miscimprovements – chrylis -cautiouslyoptimistic- Jul 31 '19 at 18:40
  • @chrylis I was originally attempting to compile using 2.4.5 and had the same issue. Thanks for your link! "Groovy has been improving JSR-308 support over recent versions. As part of implementing the new grammar, additional support has been added." Does that mean that Groovy has never supported JSR 308, or is it just Groovy 3? – John Jekyllson Jul 31 '19 at 19:07
  • My guess is it's not been fully supported; I've never used JSR 308 myself, so I can't say. Have you tried a 2.5? – chrylis -cautiouslyoptimistic- Jul 31 '19 at 19:11
  • Why are you trying to use the JSR 308 Type Annotations Compiler? Type annotations have been supported in javac since Java 8 was released in March 2014. The only reason to use the Type Annotations Compiler it is if your code must compile with a Java 7 compiler, but you want to use type annotations. This is explained at its [homepage](https://checkerframework.org/jsr308/). – mernst Aug 01 '19 at 13:12

1 Answers1

0

I have retried with multiple versions of groovy. It did not work with a 2.5 version, but with 2.0.0 my command actually technically compiles. Unfortunately, there are some other compatibility problems beyond this basic example and I would not recommend that anyone try to make groovy work with JSR-308 if it is not necessary.