pinpoint-apm / pinpoint

APM, (Application Performance Management) tool for large-scale distributed systems.
https://pinpoint-apm.gitbook.io/
Apache License 2.0
13.29k stars 3.75k forks source link

ClassFormatError-->Duplicate interface name "com/navercorp/pinpoint/bootstrap/async/AsyncContextAccessor" #11012

Open philippe-granet opened 1 month ago

philippe-granet commented 1 month ago

Prerequisites

Please check the FAQ, and search existing issues for similar questions before creating a new issue.YOU MAY DELETE THIS PREREQUISITES SECTION.

What version of pinpoint are you using?

2.5.3

Describe the bug

Application (Springboot 2.7) failed to start with error: ClassFormatError-->Duplicate interface name "com/navercorp/pinpoint/bootstrap/async/AsyncContextAccessor"

I found a similar issue on Skywalking APM: https://github.com/apache/skywalking/issues/6172

Logs

05/13/2024 19:36:29.837 [adc5-dev,,,] ERROR o.s.b.SpringApplication - Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.[redacted].outbox.OutboxConfiguration' defined in BeanDefinition defined in null: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.[redacted].outbox.OutboxConfiguration$$EnhancerBySpringCGLIB$$40bebe57: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.ClassFormatError-->Duplicate interface name "com/navercorp/pinpoint/bootstrap/async/AsyncContextAccessor" in class file fr/[redacted]/outbox/OutboxConfiguration$$EnhancerBySpringCGLIB$$d711c992
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:209)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:936)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:591)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at com.[redacted].Application.main(Application.java:47)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.[redacted].outbox.OutboxConfiguration$$EnhancerBySpringCGLIB$$40bebe57: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.ClassFormatError-->Duplicate interface name "com/navercorp/pinpoint/bootstrap/async/AsyncContextAccessor" in class file fr/[redacted]/outbox/OutboxConfiguration$$EnhancerBySpringCGLIB$$d711c992
    at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:209)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
    at org.springframework.aop.scope.ScopedProxyFactoryBean.setBeanFactory(ScopedProxyFactoryBean.java:117)
    at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.setBeanFactory(GenericScope.java:449)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1826)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
    ... 21 common frames omitted
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.ClassFormatError-->Duplicate interface name "com/navercorp/pinpoint/bootstrap/async/AsyncContextAccessor" in class file fr/[redacted]/outbox/OutboxConfiguration$$EnhancerBySpringCGLIB$$d711c992
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:511)
    at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363)
    at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585)
    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(Unknown Source)
    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.proxy.Enhancer.createHelper(Enhancer.java:572)
    at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:419)
    at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)
    at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:206)
    ... 27 common frames omitted
Caused by: java.lang.ClassFormatError: Duplicate interface name "com/navercorp/pinpoint/bootstrap/async/AsyncContextAccessor" in class file fr/[redacted]/outbox/OutboxConfiguration$$EnhancerBySpringCGLIB$$d711c992
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.System$2.defineClass(Unknown Source)
    at java.base/java.lang.invoke.MethodHandles$Lookup.defineClass(Unknown Source)
    at java.base/jdk.internal.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:506)
    ... 41 common frames omitted
jaehong-kim commented 1 month ago

@philippe-granet Could you please share the class code 'com.[redacted].outbox.OutboxConfiguration'? @Async is included? or Reactor ?

philippe-granet commented 1 month ago

@jaehong-kim The problem is perhaps caused by the @RefreshScope annotation, when bean is reloaded. https://cloud.spring.io/spring-cloud-static/spring-cloud.html Refresh scope beans are lazy proxies that initialize when they are used (i.e. when a method is called), and the scope acts as a cache of initialized values

package com.[REDACTED];

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

@AutoConfiguration
@ComponentScan
@EnableScheduling
@EnableConfigurationProperties(OutboxProperties.class)
@RefreshScope
public class OutboxConfiguration implements SchedulingConfigurer {

    @Autowired
    @Qualifier("asyncThreadPoolTaskScheduler")
    private TaskScheduler taskScheduler;

    @Autowired
    private ApplicationContext springContext;

    private static final Logger LOG = LoggerFactory.getLogger(OutboxConfiguration.class);

    @Autowired
    private OutboxProperties properties;

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        ...
    }

    @EventListener
    public void onRefreshScopeRefreshed(final RefreshScopeRefreshedEvent event) {
        LOG.info("OutboxConfiguration : Refresh scope bean lazy proxy initialization.");
    }
}