Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanInstantiationException caused by IllegalAccessError when running test since upgrading to 4.7.0 #11344

Closed
mplanchant opened this issue Nov 15, 2024 · 5 comments · Fixed by #11347

Comments

@mplanchant
Copy link

Expected Behavior

Test, annotated with @MicronautTest fails when initialising context.

java.lang.IllegalAccessError: class com.package.$MyClass$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.package.$MyClass$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')

MyClass is annotated with @Introspected.

Problem was not occurring prior to upgrading to 4.7.0 (and Gradle plugin to 4.4.4).

Actual Behaviour

io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [com.package.RequestHandlerTest] could not be loaded: Error instantiating bean of type  [com.package.RequestHandlerTest]

Message: Failed to load a service: java.lang.IllegalAccessError: class com.package.$MyClass$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.package.$MyClass$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
Path Taken: new RequestHandlerTest()

	at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:2000)
	at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:314)
	at io.micronaut.context.DefaultBeanContext.configureAndStartContext(DefaultBeanContext.java:3318)
	at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:345)
	at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:216)
	at io.micronaut.test.extensions.AbstractMicronautExtension.startApplicationContext(AbstractMicronautExtension.java:507)
	at io.micronaut.test.extensions.AbstractMicronautExtension.beforeClass(AbstractMicronautExtension.java:346)
	at io.micronaut.test.extensions.junit5.MicronautJunit5Extension.beforeAll(MicronautJunit5Extension.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [com.package.RequestHandlerTest]

Message: Failed to load a service: java.lang.IllegalAccessError: class com.package.$MyClass$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.package.$MyClass$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
Path Taken: new RequestHandlerTest()
	at io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2349)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2304)
	at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2316)
	at io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3127)
	at io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:80)
	at io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:3029)
	at io.micronaut.context.DefaultBeanContext.initializeEagerBean(DefaultBeanContext.java:2702)
	at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1994)
	... 8 more
Caused by: io.micronaut.core.io.service.SoftServiceLoader$ServiceLoadingException: Failed to load a service: java.lang.IllegalAccessError: class com.package.$MyClass$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.package.$MyClass$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
	at io.micronaut.core.io.service.ServiceScanner$ServiceInstanceLoader.collect(ServiceScanner.java:244)
	at io.micronaut.core.io.service.ServiceScanner$DefaultServiceCollector.collect(ServiceScanner.java:157)
	at io.micronaut.core.io.service.SoftServiceLoader.collectDynamicServices(SoftServiceLoader.java:199)
	at io.micronaut.core.io.service.SoftServiceLoader.collectAll(SoftServiceLoader.java:174)
	at io.micronaut.core.beans.DefaultBeanIntrospector.getIntrospections(DefaultBeanIntrospector.java:117)
	at io.micronaut.core.beans.DefaultBeanIntrospector.findIntrospection(DefaultBeanIntrospector.java:88)
	at io.micronaut.core.reflect.InstantiationUtils.tryInstantiate(InstantiationUtils.java:165)
	at io.micronaut.context.conditions.MatchesCustomCondition.matches(MatchesCustomCondition.java:58)
	at io.micronaut.context.AbstractInitializableBeanDefinitionAndReference.matches(AbstractInitializableBeanDefinitionAndReference.java:111)
	at io.micronaut.context.AbstractInitializableBeanDefinitionAndReference.isEnabled(AbstractInitializableBeanDefinitionAndReference.java:94)
	at io.micronaut.context.DefaultBeanContext$BeanDefinitionProducer.isDefinitionEnabled(DefaultBeanContext.java:4294)
	at io.micronaut.context.DefaultBeanContext$BeanDefinitionProducer.isDefinitionEnabled(DefaultBeanContext.java:4274)
	at io.micronaut.context.DefaultBeanContext.collectBeanCandidates(DefaultBeanContext.java:2167)
	at io.micronaut.context.DefaultBeanContext.findBeanCandidates(DefaultBeanContext.java:2135)
	at io.micronaut.context.DefaultBeanContext.findConcreteCandidateNoCache(DefaultBeanContext.java:3184)
	at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:3168)
	at io.micronaut.context.DefaultBeanContext.findBeanDefinition(DefaultBeanContext.java:2777)
	at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2746)
	at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1745)
	at io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:89)
	at io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2188)
	at io.micronaut.context.AbstractInitializableBeanDefinition.getBeanForField(AbstractInitializableBeanDefinition.java:1694)
	at com.package.$RequestHandlerTest$Definition.inject(Unknown Source)
	at com.package.$RequestHandlerTest$Definition.instantiate(Unknown Source)
	at io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2334)
	... 15 more
Caused by: io.micronaut.core.io.service.SoftServiceLoader$ServiceLoadingException: java.lang.IllegalAccessError: class com.package.$MyClass$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.package.$MyClass$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
	at io.micronaut.core.io.service.SoftServiceLoader.lambda$collectDynamicServices$2(SoftServiceLoader.java:195)
	at io.micronaut.core.io.service.ServiceScanner$ServiceInstanceLoader.compute(ServiceScanner.java:235)
	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at java.base/java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
	at --- Async.Stack.Trace --- (captured by IntelliJ IDEA debugger)
	at java.base/java.util.concurrent.ForkJoinTask.fork(ForkJoinTask.java)
	at io.micronaut.core.io.service.ServiceScanner$DefaultServiceCollector.compute(ServiceScanner.java:135)
	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at java.base/java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
Caused by: java.lang.IllegalAccessError: class com.package.$MyClass$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.package.$MyClass$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
	at com.package.$MyClass$Introspection.<clinit>(Unknown Source)
	at java.base/jdk.internal.misc.Unsafe.allocateInstance(Native Method)
	at java.base/java.lang.invoke.DirectMethodHandle.allocateInstance(DirectMethodHandle.java:501)
	at io.micronaut.core.io.service.SoftServiceLoader.lambda$collectDynamicServices$2(SoftServiceLoader.java:187)
	... 14 more

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

4.7.0

@graemerocher
Copy link
Contributor

do you have a reproducer?

@mplanchant
Copy link
Author

do you have a reproducer?

I'll put one together.

mplanchant added a commit to mplanchant/micronaut-core-11344 that referenced this issue Nov 15, 2024
@mplanchant
Copy link
Author

mplanchant commented Nov 15, 2024

Reproducer here https://github.com/mplanchant/micronaut-core-11344/. If you roll the version back to 4.6.0, the failing test will pass.

@graemerocher
Copy link
Contributor

thanks, looking into it. Workaround is to specify

@Introspected(builder =
    @Introspected.IntrospectionBuilder(
        builderClass = MyEntity.MyEntityBuilder.class
    )
)

@mplanchant
Copy link
Author

mplanchant commented Dec 5, 2024

@graemerocher I'm still seeing a error when I upgrade the reproducer to 4.7.1.

Failed to load a service: java.lang.IllegalAccessError: class com.example.$MyEntity$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.example.$MyEntity$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
io.micronaut.core.io.service.SoftServiceLoader$ServiceLoadingException: Failed to load a service: java.lang.IllegalAccessError: class com.example.$MyEntity$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.example.$MyEntity$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
	at io.micronaut.core.io.service.ServiceScanner$ServiceInstanceLoader.collect(ServiceScanner.java:244)
	at io.micronaut.core.io.service.ServiceScanner$DefaultServiceCollector.collect(ServiceScanner.java:157)
	at io.micronaut.core.io.service.SoftServiceLoader.collectDynamicServices(SoftServiceLoader.java:199)
	at io.micronaut.core.io.service.SoftServiceLoader.collectAll(SoftServiceLoader.java:174)
	at io.micronaut.core.beans.DefaultBeanIntrospector.getIntrospections(DefaultBeanIntrospector.java:117)
	at io.micronaut.core.beans.DefaultBeanIntrospector.findIntrospection(DefaultBeanIntrospector.java:88)
	at io.micronaut.core.reflect.InstantiationUtils.tryInstantiate(InstantiationUtils.java:165)
	at io.micronaut.context.conditions.MatchesCustomCondition.matches(MatchesCustomCondition.java:58)
	at io.micronaut.context.AbstractInitializableBeanDefinitionAndReference.matches(AbstractInitializableBeanDefinitionAndReference.java:111)
	at io.micronaut.context.AbstractInitializableBeanDefinitionAndReference.isEnabled(AbstractInitializableBeanDefinitionAndReference.java:94)
	at io.micronaut.context.DefaultBeanContext$BeanDefinitionProducer.isDefinitionEnabled(DefaultBeanContext.java:4294)
	at io.micronaut.context.DefaultBeanContext$BeanDefinitionProducer.isDefinitionEnabled(DefaultBeanContext.java:4274)
	at io.micronaut.context.DefaultBeanContext$BeanDefinitionProducer.isDefinitionEnabled(DefaultBeanContext.java:4267)
	at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:2008)
	at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:314)
	at io.micronaut.context.DefaultBeanContext.configureAndStartContext(DefaultBeanContext.java:3318)
	at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:345)
	at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:216)
	at io.micronaut.test.extensions.AbstractMicronautExtension.startApplicationContext(AbstractMicronautExtension.java:507)
	at io.micronaut.test.extensions.AbstractMicronautExtension.beforeClass(AbstractMicronautExtension.java:346)
	at io.micronaut.test.extensions.junit5.MicronautJunit5Extension.beforeAll(MicronautJunit5Extension.java:84)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: io.micronaut.core.io.service.SoftServiceLoader$ServiceLoadingException: java.lang.IllegalAccessError: class com.example.$MyEntity$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.example.$MyEntity$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
	at io.micronaut.core.io.service.SoftServiceLoader.lambda$collectDynamicServices$2(SoftServiceLoader.java:195)
	at io.micronaut.core.io.service.ServiceScanner$ServiceInstanceLoader.compute(ServiceScanner.java:235)
	at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
Caused by: java.lang.IllegalAccessError: class com.example.$MyEntity$Introspection tried to access protected method 'void java.lang.Record.<init>()' (com.example.$MyEntity$Introspection is in unnamed module of loader 'app'; java.lang.Record is in module java.base of loader 'bootstrap')
	at com.example.$MyEntity$Introspection.<clinit>(Unknown Source)
	at java.base/jdk.internal.misc.Unsafe.allocateInstance(Native Method)
	at java.base/java.lang.invoke.DirectMethodHandle.allocateInstance(DirectMethodHandle.java:501)
	at io.micronaut.core.io.service.SoftServiceLoader.lambda$collectDynamicServices$2(SoftServiceLoader.java:187)
	... 7 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
2 participants