Closed
Description
Versions
- Spring Version 5.3.16
- JDK Version : Eclipse Adoptium Temurin-17.0.2+
Overview
create some bean (com.alibaba.druid.filter.stat.StatFilter
) with class extends javax.management.NotificationBroadcasterSupport
.
AnnotationMBeanExporter
Bean:
@Configuration
public class TestJmxBean {
private static final Logger LOG = LoggerFactory.getLogger(TestJmxBean.class);
@Bean
@Lazy(false)
public AnnotationMBeanExporter annotationMBeanExporter() {
LOG.info("TestJmxBean.annotationMBeanExporter|REPLACE_EXISTING");
AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);
return exporter;
}
}
the demo project in the attach file:
springquartzdemo.zip
Steps to Reproduce
- import the project to ide.
- run gradlew build
- use jdk 8 run the main class success.
- use jdk 17 run the main class fail
- see the stack trace。
- cause : the package name
$javax.management
is not equals tojavax.management
?
D:\Java\ide\workspace\springquartzdemo>D:\Java\jdk-17.0.2+8\bin\java -verbose:gc --add-opens java.management/javax.management=ALL-UNNAMED -cp dist/conf;dist/lib/* -Dcom.sun.management.jmxremote.port=19881 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dfile.encoding=UTF-8 com.lizongbo.springdemo.SpringQuartzBugTest
[0.025s][info][gc] Using G1
[0.870s][info][gc] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 23M->5M(128M) 7.105ms
2022-03-05 21:39:11,366 main INFO The lookups option will be ignored. Message Lookups are no longer supported.
[1.398s][info][gc] GC(1) Pause Young (Normal) (G1 Evacuation Pause) 29M->7M(128M) 6.926ms
2022-03-05 21:39:11.987 [main] INFO TestJmxBean.annotationMBeanExporter(TestJmxBean.java:17) - TestJmxBean.annotationMBeanExporter|REPLACE_EXISTING
Exception in thread "main" org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [stat-filter] with key 'stat-filter'; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalArgumentException-->$javax.management.NotificationBroadcasterSupport$$FastClassBySpringCGLIB$$824990df not in same package as lookup class
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:626)
at org.springframework.jmx.export.MBeanExporter.lambda$registerBeans$2(MBeanExporter.java:552)
at java.base/java.util.HashMap.forEach(HashMap.java:1421)
at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:552)
at org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:435)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:972)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at com.lizongbo.springdemo.SpringQuartzBugTest.main(SpringQuartzBugTest.java:18)
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalArgumentException-->$javax.management.NotificationBroadcasterSupport$$FastClassBySpringCGLIB$$824990df not in same package as lookup class
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:580)
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108)
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319)
at org.springframework.cglib.reflect.FastClass$Generator.create(FastClass.java:65)
at org.springframework.cglib.proxy.MethodProxy.helper(MethodProxy.java:135)
at org.springframework.cglib.proxy.MethodProxy.init(MethodProxy.java:76)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:216)
at org.springframework.aop.framework.CglibAopProxy$DynamicUnadvisedInterceptor.intercept(CglibAopProxy.java:481)
at com.lizongbo.springdemo.SqlChcekStatFilter$$EnhancerBySpringCGLIB$$f714b8d3.getNotificationInfo(<generated>)
at java.management/com.sun.jmx.mbeanserver.MBeanIntrospector.findNotifications(MBeanIntrospector.java:447)
at java.management/com.sun.jmx.mbeanserver.MBeanIntrospector.getMBeanInfo(MBeanIntrospector.java:393)
at java.management/com.sun.jmx.mbeanserver.MBeanSupport.<init>(MBeanSupport.java:139)
at java.management/com.sun.jmx.mbeanserver.StandardMBeanSupport.<init>(StandardMBeanSupport.java:60)
at java.management/com.sun.jmx.mbeanserver.Introspector.makeDynamicMBean(Introspector.java:194)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:893)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:320)
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:523)
at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:138)
at org.springframework.jmx.export.MBeanExporter.registerLazyInit(MBeanExporter.java:715)
at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:597)
... 8 more
Caused by: java.lang.IllegalArgumentException: $javax.management.NotificationBroadcasterSupport$$FastClassBySpringCGLIB$$824990df not in same package as lookup class
at java.base/java.lang.invoke.MethodHandleStatics.newIllegalArgumentException(MethodHandleStatics.java:167)
at java.base/java.lang.invoke.MethodHandles$Lookup$ClassFile.newInstance(MethodHandles.java:2283)
at java.base/java.lang.invoke.MethodHandles$Lookup.makeClassDefiner(MethodHandles.java:2318)
at java.base/java.lang.invoke.MethodHandles$Lookup.defineClass(MethodHandles.java:1843)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:577)
... 34 more
[1.809s][info][gc] GC(2) Pause Young (Concurrent Start) (Metadata GC Threshold) 32M->9M(128M) 5.691ms
[1.811s][info][gc] GC(3) Concurrent Mark Cycle
[1.821s][info][gc] GC(3) Pause Remark 10M->10M(40M) 2.380ms
[1.823s][info][gc] GC(3) Pause Cleanup 10M->10M(40M) 0.067ms
[1.826s][info][gc] GC(3) Concurrent Mark Cycle 15.156ms