google / rejoiner

Generates a unified GraphQL schema from gRPC microservices and other Protobuf sources
https://google.github.io/rejoiner/
Apache License 2.0
3.67k stars 143 forks source link

Exception when starting up Spring Boot 2.7.7/Java 17 app with Rejoiner #131

Closed lewimuchiri closed 1 year ago

lewimuchiri commented 1 year ago

Hi, i'm getting this exception when starting up my app:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.kickstart.execution.config.GraphQLSchemaProvider]: Factory method 'schemaProvider' threw exception; nested exception is com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.24.jar:5.3.24]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.24.jar:5.3.24]
    ... 19 common frames omitted
Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2053) ~[guava-31.1-jre.jar:na]
    at com.google.common.cache.LocalCache.get(LocalCache.java:3966) ~[guava-31.1-jre.jar:na]
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3989) ~[guava-31.1-jre.jar:na]
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4950) ~[guava-31.1-jre.jar:na]
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4956) ~[guava-31.1-jre.jar:na]
    at com.google.inject.internal.FailableCache.get(FailableCache.java:48) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:50) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:138) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:550) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:887) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:808) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:285) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:217) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:893) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.BoundProviderFactory.notify(BoundProviderFactory.java:50) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ProcessedBindingData.runCreationListeners(ProcessedBindingData.java:50) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:134) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107) ~[guice-4.1.0.jar:na]
    at com.google.inject.Guice.createInjector(Guice.java:99) ~[guice-4.1.0.jar:na]
    at com.google.inject.Guice.createInjector(Guice.java:73) ~[guice-4.1.0.jar:na]
    at com.google.inject.Guice.createInjector(Guice.java:62) ~[guice-4.1.0.jar:na]
    at app.rejoiner.config.RejoinerConfig.schemaProvider(RejoinerConfig.java:39) ~[main/:na]
    at app.rejoiner.config.RejoinerConfig$$EnhancerBySpringCGLIB$$8559a62e.CGLIB$schemaProvider$1(<generated>) ~[main/:na]
    at app.rejoiner.config.RejoinerConfig$$EnhancerBySpringCGLIB$$8559a62e$$FastClassBySpringCGLIB$$f606633d.invoke(<generated>) ~[main/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.24.jar:5.3.24]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.24.jar:5.3.24]
    at app.rejoiner.config.RejoinerConfig$$EnhancerBySpringCGLIB$$8559a62e.schemaProvider(<generated>) ~[main/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.24.jar:5.3.24]
    ... 20 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.getProtectionDomain(FastClass.java:73) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:206) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:65) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:252) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.BytecodeGen.newFastClassForMember(BytecodeGen.java:203) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:53) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:158) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:90) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33) ~[guice-4.1.0.jar:na]
    at com.google.inject.internal.FailableCache$1.load(FailableCache.java:37) ~[guice-4.1.0.jar:na]
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3533) ~[guava-31.1-jre.jar:na]
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2282) ~[guava-31.1-jre.jar:na]
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2159) ~[guava-31.1-jre.jar:na]
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2049) ~[guava-31.1-jre.jar:na]
    ... 51 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @1b7cc17c
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) ~[na:na]
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) ~[na:na]
    at com.google.inject.internal.cglib.core.$ReflectUtils$1.run(ReflectUtils.java:52) ~[guice-4.1.0.jar:na]
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) ~[na:na]
    at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>(ReflectUtils.java:42) ~[guice-4.1.0.jar:na]
    ... 67 common frames omitted

Here is my build.gradle.kts:

image

My configuration class is as follows:

@Configuration
public class RejoinerConfig {
    private final Injector injector;

    {
        injector = Guice.createInjector(
                new SchemaProviderModule(),
                new GrpcClientModule(),
                new GraphQlSchemaModule()
        );
    }

    @Bean
    public GraphQLSchemaProvider schemaProvider() {
        GraphQLSchema schema = injector.getInstance(Key.get(GraphQLSchema.class, Schema.class));
        return new DefaultGraphQLSchemaProvider(schema);
    }

    @Bean
    public Instrumentation instrumentation() {
        return GuavaListenableFutureSupport.listenableFutureInstrumentation();
    }

}

The Guice.createInjector() line is the offending code. Any leads? Thanks

lewimuchiri commented 1 year ago

The problem is with Java 17. The project works as-is in Java 11, but for Java 17, you have to use guice version 5.1.0 (it's the one I tested with). Do not rely on the guice that comes with Rejoiner

    implementation("com.google.api.graphql:rejoiner:0.3.1") {
        exclude(group = "com.google.inject", module = "guice")
    }
    implementation("com.google.inject:guice:5.1.0")
lewimuchiri commented 1 year ago

Forked project and upgraded its dependencies. Now works with Java 17 and graphql-java versions above 16.2 (due to Scalars.GraphQLLong which was moved to Extended Scalars library)