Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7587

Groovy 2.2 and 2.4 all fail to execute almost any script with Java 9 JIGSAW preview builds

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.2.2, 2.4.4
    • Fix Version/s: 2.4.6
    • Component/s: groovy-runtime
    • Labels:
    • Environment:
      java version "1.9.0-ea"
      Java(TM) SE Runtime Environment (build 1.9.0-ea-jigsaw-nightly-h3337-20150908-b80)
      Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-jigsaw-nightly-h3337-20150908-b80, mixed mode)

      Description

      The Lucene project successfully made their code running with the recently announced preview builds of Java 9. Unfortunately some parts of Lucene's build script and also the build of the Policeman's ForbiddenAPI checker (https://github.com/policeman-tools/forbidden-apis/) use groovy to execute some stuff that does not work with plain Ant. Similar issues are seen by Elasticsearch's scripting support plugin.

      Unfortunately even simple scripts fail quite often. The issue always looks like this:

      def temp = ClassLoader.getSystemClassLoader()
      temp.toString()
      
      java.lang.reflect.InaccessibleObjectException: Unable to make member of class jdk.internal.misc.ClassLoaders$AppClassLoader accessible:  module java.base does not export jdk.internal.misc to <unnamed module @1a6f5124>
              at sun.reflect.Reflection.throwInaccessibleObjectException(java.base@9.0/Reflection.java:462)
              at java.lang.reflect.AccessibleObject.checkCanSetAccessible(java.base@9.0/AccessibleObject.java:194)
              at java.lang.reflect.AccessibleObject.setAccessible(java.base@9.0/AccessibleObject.java:157)
              at org.codehaus.groovy.reflection.CachedConstructor$1.run(CachedConstructor.java:44)
              at java.security.AccessController.doPrivileged(java.base@9.0/Native Method)
              at org.codehaus.groovy.reflection.CachedConstructor.<init>(CachedConstructor.java:42)
              at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:79)
              at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:69)
              at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:49)
              at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:36)
              at org.codehaus.groovy.reflection.CachedClass.getConstructors(CachedClass.java:268)
              at groovy.lang.MetaClassImpl.<init>(MetaClassImpl.java:218)
              at groovy.lang.MetaClassImpl.<init>(MetaClassImpl.java:228)
              at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createNormalMetaClass(MetaClassRegistry.java:171)
              at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createWithCustomLookup(MetaClassRegistry.java:161)
              at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.create(MetaClassRegistry.java:144)
              at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:253)
              at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:285)
              at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:295)
              at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:261)
              at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:871)
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:125)
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:166)
              at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
              at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
              at generate-deprecated.run(generate-deprecated.groovy:20)
              at org.codehaus.groovy.ant.Groovy.parseAndRunScript(Groovy.java:501)
              at org.codehaus.groovy.ant.Groovy.execGroovy(Groovy.java:448)
              at org.codehaus.groovy.ant.Groovy.execute(Groovy.java:313)
      

      This always happens under the following circumstances. You have a public Object accessible from everywhere in the JDK. This object is working like a factory and creates an implementation of an abstract class. In the above example this is a classloader (abstract class). This returned instance is of course some JDK-internal class and the user code is intended to only call the visible methods on it.

      Unfortunately groovy tries in the second line to create a metaclass to get "full insight" of this internal class. For that it tries to make everything accessible. And with Java 9 including JIGSAW this is no longer possible. You can use the APIs provided by the internal implementation, but you are not allowed to do any non-public stuff. This is disallowed by the Java module system and there is no way around (unless you disable the module system completely, which will not work in all cases in Java 9 once it is released).

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              thetaphi Uwe Schindler
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: