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

CodeGenerationException thrown when using AnnotationMBeanExporter on JDK 17 #28138

Closed
lizongbo opened this issue Mar 5, 2022 · 4 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches status: feedback-provided Feedback has been provided type: bug A general bug
Milestone

Comments

@lizongbo
Copy link

lizongbo commented Mar 5, 2022

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

  1. import the project to ide.
  2. run gradlew build
  3. use jdk 8 run the main class success.
  4. use jdk 17 run the main class fail
  5. see the stack trace。
  6. cause : the package name $javax.management is not equals to javax.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

bug004

bug005

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 5, 2022
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Mar 5, 2022
@sbrannen sbrannen changed the title CodeGenerationException: java.lang.IllegalArgumentException when use AnnotationMBeanExporter on JDK 17 CodeGenerationException thrown when using AnnotationMBeanExporter on JDK 17 Mar 5, 2022
@sbrannen sbrannen added this to the Triage Queue milestone Mar 5, 2022
@sbrannen
Copy link
Member

@rstoyanchev
Copy link
Contributor

Could you re-attach the demo project? The link is no longer working.

@rstoyanchev rstoyanchev assigned jhoeller and unassigned jhoeller and sbrannen Mar 29, 2022
@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Mar 29, 2022
@jhoeller jhoeller added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 29, 2022
@jhoeller jhoeller modified the milestones: Triage Queue, 5.3.18 Mar 29, 2022
@snicoll snicoll modified the milestones: 5.3.18, 5.3.19 Mar 31, 2022
@lizongbo
Copy link
Author

lizongbo commented Apr 1, 2022

springquartzdemo.zip

this is the demo for reproduce bug

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 1, 2022
@jhoeller
Copy link
Contributor

jhoeller commented Apr 4, 2022

This turns out to be a follow-up to #27490 where we applied a fallback code path for CGLIB fast-class generation failures. In some AOP configuration scenarios, CglibAopProxy uses special optimized interceptors that unfortunately always insist on the fast-class; I've added the same fallback code path there so that all variants of CGLIB MethodProxy invocations are covered now.

@jhoeller jhoeller added the status: backported An issue that has been backported to maintenance branches label Apr 4, 2022
jhoeller added a commit that referenced this issue Apr 8, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 26, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 26, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 26, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 26, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 26, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 26, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 26, 2022
RangerRick pushed a commit to OpenNMS/spring-framework that referenced this issue Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches status: feedback-provided Feedback has been provided type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants