You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/12/22 16:21:00 UTC
[jira] [Created] (GROOVY-9873) STC: SAM type or functional
interface referenced from a method is not visible from class loader
Eric Milles created GROOVY-9873:
-----------------------------------
Summary: STC: SAM type or functional interface referenced from a method is not visible from class loader
Key: GROOVY-9873
URL: https://issues.apache.org/jira/browse/GROOVY-9873
Project: Groovy
Issue Type: Bug
Affects Versions: 4.0.0-alpha-2
Reporter: Eric Milles
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.
New test case for {{groovy.transform.stc.GenericsSTCTest}}:
{code:groovy}
// GROOVY-9803
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()
}
}
{code}
{code}
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)
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)