[ https://issues.apache.org/jira/browse/MNG-8217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17904733#comment-17904733 ]
Guillaume Nodet edited comment on MNG-8217 at 12/11/24 9:19 AM: ---------------------------------------------------------------- The ClassNotFound is caused because the ClassRealm are closed too early (tested on 4.0.0-rc-1): Realm destruction: {code} java.lang.Thread.State: RUNNABLE at java.net.URLClassLoader.close(URLClassLoader.java:345) at org.codehaus.plexus.classworlds.ClassWorld.disposeRealm(ClassWorld.java:122) at org.codehaus.plexus.classworlds.ClassWorld.disposeRealm(ClassWorld.java:114) - locked <0x29bd> (a org.codehaus.plexus.classworlds.ClassWorld) at org.apache.maven.plugin.DefaultExtensionRealmCache.flush(DefaultExtensionRealmCache.java:136) at org.apache.maven.plugin.DefaultExtensionRealmCache.dispose(DefaultExtensionRealmCache.java:149) at org.eclipse.sisu.plexus.PlexusLifecycleManager.dispose(PlexusLifecycleManager.java:370) at org.eclipse.sisu.plexus.PlexusLifecycleManager.unmanage(PlexusLifecycleManager.java:175) at org.codehaus.plexus.DefaultPlexusContainer.dispose(DefaultPlexusContainer.java:592) at org.apache.maven.cling.invoker.PlexusContainerCapsule.close(PlexusContainerCapsule.java:68) at org.apache.maven.cling.invoker.LookupContext.closeContainer(LookupContext.java:127) at org.apache.maven.cling.invoker.mvn.MavenContext.closeContainer(MavenContext.java:41) at org.apache.maven.cling.invoker.LookupInvoker$$Lambda/0x00000003012864b8.close(Unknown Source:-1) at org.apache.maven.cling.invoker.LookupContext.close(LookupContext.java:108) at org.apache.maven.cling.invoker.LookupInvoker.invoke(LookupInvoker.java:119) at org.apache.maven.cling.ClingSupport.run(ClingSupport.java:64) at org.apache.maven.cling.MavenCling.main(MavenCling.java:51) at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic(DirectMethodHandle$Holder:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008400.invoke(LambdaForm$MH:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008800.invokeExact_MT(LambdaForm$MH:-1) at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(DirectMethodHandleAccessor.java:155) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke(Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314) {code} PReDestroy call: {code} java.lang.Thread.State: RUNNABLE at com.cyrilleleclerc.maven.extension.jsr330.TestComponent.preDestroy(TestComponent.java:23) at java.lang.invoke.LambdaForm$DMH/0x0000000301289000.invokeVirtual(LambdaForm$DMH:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301488000.invoke(LambdaForm$MH:-1) at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder:-1) at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(DirectMethodHandleAccessor.java:153) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke(Method.java:580) at org.eclipse.sisu.bean.BeanLifecycle.stop(BeanLifecycle.java:133) at org.eclipse.sisu.bean.LifecycleManager.unmanage(LifecycleManager.java:85) at org.eclipse.sisu.plexus.PlexusLifecycleManager.unmanage(PlexusLifecycleManager.java:177) at org.codehaus.plexus.DefaultPlexusContainer.dispose(DefaultPlexusContainer.java:592) at org.apache.maven.cling.invoker.PlexusContainerCapsule.close(PlexusContainerCapsule.java:68) at org.apache.maven.cling.invoker.LookupContext.closeContainer(LookupContext.java:127) at org.apache.maven.cling.invoker.mvn.MavenContext.closeContainer(MavenContext.java:41) at org.apache.maven.cling.invoker.LookupInvoker$$Lambda/0x00000003012864b8.close(Unknown Source:-1) at org.apache.maven.cling.invoker.LookupContext.close(LookupContext.java:108) at org.apache.maven.cling.invoker.LookupInvoker.invoke(LookupInvoker.java:119) at org.apache.maven.cling.ClingSupport.run(ClingSupport.java:64) at org.apache.maven.cling.MavenCling.main(MavenCling.java:51) at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic(DirectMethodHandle$Holder:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008400.invoke(LambdaForm$MH:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008800.invokeExact_MT(LambdaForm$MH:-1) at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(DirectMethodHandleAccessor.java:155) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke(Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314) {code} was (Author: gnt): There's another problem: the ClassRealm are closed too early, at least on 4.0.0-rc-1: Realm destruction: {code} java.lang.Thread.State: RUNNABLE at java.net.URLClassLoader.close(URLClassLoader.java:345) at org.codehaus.plexus.classworlds.ClassWorld.disposeRealm(ClassWorld.java:122) at org.codehaus.plexus.classworlds.ClassWorld.disposeRealm(ClassWorld.java:114) - locked <0x29bd> (a org.codehaus.plexus.classworlds.ClassWorld) at org.apache.maven.plugin.DefaultExtensionRealmCache.flush(DefaultExtensionRealmCache.java:136) at org.apache.maven.plugin.DefaultExtensionRealmCache.dispose(DefaultExtensionRealmCache.java:149) at org.eclipse.sisu.plexus.PlexusLifecycleManager.dispose(PlexusLifecycleManager.java:370) at org.eclipse.sisu.plexus.PlexusLifecycleManager.unmanage(PlexusLifecycleManager.java:175) at org.codehaus.plexus.DefaultPlexusContainer.dispose(DefaultPlexusContainer.java:592) at org.apache.maven.cling.invoker.PlexusContainerCapsule.close(PlexusContainerCapsule.java:68) at org.apache.maven.cling.invoker.LookupContext.closeContainer(LookupContext.java:127) at org.apache.maven.cling.invoker.mvn.MavenContext.closeContainer(MavenContext.java:41) at org.apache.maven.cling.invoker.LookupInvoker$$Lambda/0x00000003012864b8.close(Unknown Source:-1) at org.apache.maven.cling.invoker.LookupContext.close(LookupContext.java:108) at org.apache.maven.cling.invoker.LookupInvoker.invoke(LookupInvoker.java:119) at org.apache.maven.cling.ClingSupport.run(ClingSupport.java:64) at org.apache.maven.cling.MavenCling.main(MavenCling.java:51) at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic(DirectMethodHandle$Holder:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008400.invoke(LambdaForm$MH:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008800.invokeExact_MT(LambdaForm$MH:-1) at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(DirectMethodHandleAccessor.java:155) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke(Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314) {code} PReDestroy call: {code} java.lang.Thread.State: RUNNABLE at com.cyrilleleclerc.maven.extension.jsr330.TestComponent.preDestroy(TestComponent.java:23) at java.lang.invoke.LambdaForm$DMH/0x0000000301289000.invokeVirtual(LambdaForm$DMH:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301488000.invoke(LambdaForm$MH:-1) at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder:-1) at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(DirectMethodHandleAccessor.java:153) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke(Method.java:580) at org.eclipse.sisu.bean.BeanLifecycle.stop(BeanLifecycle.java:133) at org.eclipse.sisu.bean.LifecycleManager.unmanage(LifecycleManager.java:85) at org.eclipse.sisu.plexus.PlexusLifecycleManager.unmanage(PlexusLifecycleManager.java:177) at org.codehaus.plexus.DefaultPlexusContainer.dispose(DefaultPlexusContainer.java:592) at org.apache.maven.cling.invoker.PlexusContainerCapsule.close(PlexusContainerCapsule.java:68) at org.apache.maven.cling.invoker.LookupContext.closeContainer(LookupContext.java:127) at org.apache.maven.cling.invoker.mvn.MavenContext.closeContainer(MavenContext.java:41) at org.apache.maven.cling.invoker.LookupInvoker$$Lambda/0x00000003012864b8.close(Unknown Source:-1) at org.apache.maven.cling.invoker.LookupContext.close(LookupContext.java:108) at org.apache.maven.cling.invoker.LookupInvoker.invoke(LookupInvoker.java:119) at org.apache.maven.cling.ClingSupport.run(ClingSupport.java:64) at org.apache.maven.cling.MavenCling.main(MavenCling.java:51) at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic(DirectMethodHandle$Holder:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008400.invoke(LambdaForm$MH:-1) at java.lang.invoke.LambdaForm$MH/0x0000000301008800.invokeExact_MT(LambdaForm$MH:-1) at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(DirectMethodHandleAccessor.java:155) at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.lang.reflect.Method.invoke(Method.java:580) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314) {code} > `ClassNotFoundException` in `@PreDestroy` method when Maven extension > declared in `pom.xml` > ------------------------------------------------------------------------------------------- > > Key: MNG-8217 > URL: https://issues.apache.org/jira/browse/MNG-8217 > Project: Maven > Issue Type: Bug > Components: Core > Affects Versions: 3.9.8 > Reporter: Cyrille Le Clerc > Priority: Major > Fix For: 4.0.0-rc-2 > > > The `{{{}@PreDestroy{}}}` method of JSR 330 based Maven extensions fail with > a `{{{}ClassNotFoundException{}}}` when the extension is declared through the > `{{{}<build><extensions>...</extensions></build>{}}}`. > The problem doesn't happen when the Maven extension is declared through the > `{{{}.mvn/extensions.xml{}}}` file or `{{{}mvn > -Dmaven.ext.class.path=...{}}}` command line arg. > This suggest the classes of the extension are unloaded too early, before > `{{{}@PreDestroy{}}}` is invoked, when when the extension is declared through > the `{{{}<build><extensions>...</extensions></build>{}}}`. > Test case: > * > [https://github.com/cyrille-leclerc/maven-extension-test/tree/f2cc78c15e0b9a59547c111db69e2c261c9872ea/test-jsr-330-extension/src/maven-it/extension-declared-in-pom-xml] > * > [https://github.com/cyrille-leclerc/maven-extension-test/tree/f2cc78c15e0b9a59547c111db69e2c261c9872ea/test-jsr-330-extension/src/maven-it/extension-declared-in-dot-mvn-extensions-xml] > This problem impact the OpenTelemetry Maven Extension: > [opentelemetry-maven-extension NoClassDefFoundError while running package > #1391|https://github.com/open-telemetry/opentelemetry-java-contrib/issues/1391] > -- This message was sent by Atlassian Jira (v8.20.10#820010)