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

SAM type or functional interface referenced from a method is not visible from class loader

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.4.21, 2.5.14, 3.0.7, 4.0.0, 5.0.0-alpha-9
    • 3.0.23, 4.0.23, 5.0.0-alpha-10
    • None

    Description

      When type checked but not statically compiled, this case of method closure or whatever is failing for Groovy 4 but works for Groovy 3 and earlier. The line set.map(x -> x.first().intValue()) is the source. GROOVY-9803 was the original issue; when broken up into separate source units, the class loader issue appears.

      New test case for groovy.transform.stc.GenericsSTCTest:

          // GROOVY-9803, GROOVY-9873
          void testShouldUseMethodGenericType9() {
              // same as above but with separate source units
              config.with {
                  targetDirectory = File.createTempDir()
                  jointCompilationOptions = [memStub: true]
              }
              File parentDir = File.createTempDir()
              try {
                  def c = new File(parentDir, 'C.groovy')
                  c.write '''
                      class C<T> {
                          private T t
                          C(T item) {
                              t = item
                          }
                          static <U> C<U> of(U item) {
                              new C<U>(item)
                          }
                          def <V> C<V> map(F<? super T, ? super V> func) {
                              new C<V>(func.apply(t))
                          }
                      }
                  '''
                  def d = new File(parentDir, 'D.groovy')
                  d.write '''
                      class D {
                          static <W> Set<W> wrap(W o) {
                              Collections.singleton(o)
                          }
                      }
                  '''
                  def f = new File(parentDir, 'F.groovy')
                  f.write '''
                      interface F<X,Y> {
                          Y apply(X x)
                      }
                  '''
                  def g = new File(parentDir, 'G.groovy')
                  g.write '''
                      void test() {
                          def c = C.of(123)
                          def set = c.map(D.&wrap)
                          def num = set.map(x -> x.first().intValue())
                      }
                      test()
                  '''
      
                  def loader = new GroovyClassLoader(this.class.classLoader)
                  def cu = new JavaAwareCompilationUnit(config, loader)
                  cu.addSources(c, d, f, g)
                  cu.compile()
      
                  loader.loadClass('G').main()
              } finally {
                  parentDir.deleteDir()
                  config.targetDirectory.deleteDir()
              }
          }
      
          java.lang.IllegalArgumentException: F referenced from a method is not visible from class loader
              at java.base/java.lang.reflect.Proxy$ProxyBuilder.ensureVisible(Proxy.java:858)
              at java.base/java.lang.reflect.Proxy$ProxyBuilder.validateProxyInterfaces(Proxy.java:681)
              at java.base/java.lang.reflect.Proxy$ProxyBuilder.<init>(Proxy.java:627)
              at java.base/java.lang.reflect.Proxy$ProxyBuilder.<init>(Proxy.java:635)
              at java.base/java.lang.reflect.Proxy.lambda$getProxyConstructor$0(Proxy.java:415)
              at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329)
              at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205)
              at java.base/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:413)
              at java.base/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1006)
              at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
              at G.test(G.groovy:4)
              at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
              at G.run(G.groovy:7)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:566)
              at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:112)
              at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
              at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1270)
              at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1036)
              at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:1031)
              at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:1014)
              at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:444)
              at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
              at G.main(G.groovy)
      

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: