You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LambdaFetchingSupport causes NoClassDefFoundError when having multiple classloader (OSGi use case) #3113
We run into an issue with graphql.schema.fetching.LambdaFetchingSupport#mkCallFunction when having multiple classloader in our OSGi application.
The 'targetClass' parameter is already loaded with the correct classloader, but later the function call tries to load the class with the classloader of graphql-java, which produces NoClassDefFoundError.
It can also be reproduced in non-OSGi use case with a test that has two class loader:
class LambdaFetchingSupportTest extends Specification {
def "Multiple classloader in LambdaFetchingSupport"() {
when: "Load class using GroovyShell script in order to get different classloader"
def shell = new GroovyShell(this.getClass().getClassLoader())
def result = shell.run(''' package multiple.classloader.test
class MyClass{
String getName(){
return "Hello"
}
}
return new MyClass()
''', "Test.script", [])
then: "We have two different classloader now"
result.getClass().getClassLoader() != this.getClass().getClassLoader()
when:
def loader1 = this.getClass().getClassLoader()
def myClass = result.getClass()
def myClassLoader = myClass.getClassLoader()
// Loading MyClass with its loader.
myClassLoader.loadClass(myClass.getName())
then:
noExceptionThrown()
when: "Loading MyClass with another loader"
loader1.loadClass(myClass.getName())
then:
thrown(ClassNotFoundException)
when: "Also the LambdaFetchingSupport tries to load MyClass with different loader"
def function = LambdaFetchingSupport.mkCallFunction(myClass, "getName", String.class)
def expectedRes = function.apply(result)
then:
expectedRes == "Hello" // But gets NoClassDefFoundError
}
}
Activity
bbakerman commentedon Mar 13, 2023
This PR makes the Lambda support more resilient in the face of crossing class loaders
#3095
This issue has more on this
#3086
As a work around you cant turn off the Lambda support JVM wide via
graphql.schema.PropertyDataFetcherHelper#setUseLambdaFactory(false);bbakerman commentedon Mar 13, 2023
ps... Thank you for the reproduction code
bbakerman commentedon Mar 13, 2023
I am going to close this issue as a duplicate of #3086