Skip to content

LambdaFetchingSupport causes NoClassDefFoundError when having multiple classloader (OSGi use case) #3113

Closed

Description

@LanaLkv

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
    }
}

Thank you in advance!

Activity

  1. bbakerman commented on Mar 13, 2023

    @bbakerman
    Member

    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);

  2. bbakerman commented on Mar 13, 2023

    @bbakerman
    Member

    ps... Thank you for the reproduction code

  3. bbakerman commented on Mar 13, 2023

    @bbakerman
    Member

    I am going to close this issue as a duplicate of #3086

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions