alibaba / transmittable-thread-local

📌 a missing Java std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits values between threads even using thread pooling components.
https://github.com/alibaba/transmittable-thread-local
Apache License 2.0
7.66k stars 1.69k forks source link

transmittable-thread-local的JavaAgent报ClassCircularityError错误,含可复现代码 #278

Closed linfan closed 2 years ago

linfan commented 3 years ago

与 #234 应该是同一个问题,2.12.1版本在Mac下可复现。

复现代码

https://github.com/linfan/transmittable-thread-local-issue-278

JVM版本

$ java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

复现步骤

直接在代码根目录执行./gradlew clean build --info,即有一定概览会出现。

可反复执行多次,一般三次以内至少会出现一次ClassCircularityError异常。报错的堆栈会有两种情况,其中第二种情况出现的概率比较高。

第一种情况,报LinkedHashMap.java:533的位置:

2021-05-31 17:28:09.080 SEVERE [main] TtlTransformer: Fail to transform class java/util/LinkedHashMap$LinkedKeySet, cause: java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeySet
java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeySet
        at java.util.LinkedHashMap.keySet(LinkedHashMap.java:533)
        at java.io.ExpiringCache.cleanup(ExpiringCache.java:115)
        at java.io.ExpiringCache.get(ExpiringCache.java:76)
        at java.io.UnixFileSystem.canonicalize(UnixFileSystem.java:152)
        at java.io.File.getCanonicalPath(File.java:618)
        at java.io.FilePermission$1.run(FilePermission.java:224)
        at java.io.FilePermission$1.run(FilePermission.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.io.FilePermission.init(FilePermission.java:212)
        at java.io.FilePermission.<init>(FilePermission.java:299)
        at sun.net.www.protocol.file.FileURLConnection.getPermission(FileURLConnection.java:225)
        at sun.net.www.protocol.jar.JarFileFactory.getPermission(JarFileFactory.java:156)
        at sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(JarFileFactory.java:126)
        at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:81)
        at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
        at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:152)
        at java.net.URL.openStream(URL.java:1067)
        at java.lang.ClassLoader.getSystemResourceAsStream(ClassLoader.java:1324)
        at java.lang.Class.getResourceAsStream(Class.java:2221)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassClassPath.openClassfile(ClassClassPath.java:80)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:334)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPool.openClassfile(ClassPool.java:613)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile3(CtClassType.java:204)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile2(CtClassType.java:178)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getSuperclass(CtClassType.java:813)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.subclassOf(CtClassType.java:804)
        at com.alibaba.ttl.threadpool.agent.internal.transformlet.impl.TtlExecutorTransformlet.doTransform(TtlExecutorTransformlet.java:73)
        at com.alibaba.ttl.threadpool.agent.TtlTransformer.transform(TtlTransformer.java:58)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
        at java.util.LinkedHashMap.keySet(LinkedHashMap.java:533)
        at java.io.ExpiringCache.cleanup(ExpiringCache.java:115)
        at java.io.ExpiringCache.put(ExpiringCache.java:87)
        at java.io.UnixFileSystem.canonicalize(UnixFileSystem.java:173)
        at java.io.File.getCanonicalPath(File.java:618)
        at java.io.FilePermission$1.run(FilePermission.java:224)
        at java.io.FilePermission$1.run(FilePermission.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.io.FilePermission.init(FilePermission.java:212)
        at java.io.FilePermission.<init>(FilePermission.java:299)
        at sun.net.www.protocol.file.FileURLConnection.getPermission(FileURLConnection.java:225)
        at java.net.URLClassLoader.getPermissions(URLClassLoader.java:666)
        at java.security.SecureClassLoader.getProtectionDomain(SecureClassLoader.java:206)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext.reset(OutputEventListenerBackedLoggerContext.java:81)
        at org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext.<init>(OutputEventListenerBackedLoggerContext.java:46)
        at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:30)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:27)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
        at org.gradle.internal.concurrent.CompositeStoppable.<clinit>(CompositeStoppable.java:37)
        at org.gradle.internal.service.DefaultServiceRegistry$OwnServices.<init>(DefaultServiceRegistry.java:378)
        at org.gradle.internal.service.DefaultServiceRegistry.<init>(DefaultServiceRegistry.java:101)
        at org.gradle.internal.service.DefaultServiceRegistry.<init>(DefaultServiceRegistry.java:88)
        at org.gradle.internal.logging.services.LoggingServiceRegistry.<init>(LoggingServiceRegistry.java:47)
        at org.gradle.internal.logging.services.LoggingServiceRegistry$CommandLineLogging.<init>(LoggingServiceRegistry.java:157)
        at org.gradle.internal.logging.services.LoggingServiceRegistry$CommandLineLogging.<init>(LoggingServiceRegistry.java:157)
        at org.gradle.internal.logging.services.LoggingServiceRegistry.newEmbeddableLogging(LoggingServiceRegistry.java:101)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:90)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

第二种情况,报LinkedHashMap.java:543的位置:

2021-05-31 17:28:09.087 SEVERE [main] TtlTransformer: Fail to transform class java/util/LinkedHashMap$LinkedKeyIterator, cause: java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeyIterator
java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeyIterator
        at java.util.LinkedHashMap$LinkedKeySet.iterator(LinkedHashMap.java:543)
        at java.io.ExpiringCache.cleanup(ExpiringCache.java:119)
        at java.io.ExpiringCache.get(ExpiringCache.java:76)
        at java.io.UnixFileSystem.canonicalize(UnixFileSystem.java:152)
        at java.io.File.getCanonicalPath(File.java:618)
        at java.io.FilePermission$1.run(FilePermission.java:224)
        at java.io.FilePermission$1.run(FilePermission.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.io.FilePermission.init(FilePermission.java:212)
        at java.io.FilePermission.<init>(FilePermission.java:299)
        at sun.net.www.protocol.file.FileURLConnection.getPermission(FileURLConnection.java:225)
        at sun.net.www.protocol.jar.JarFileFactory.getPermission(JarFileFactory.java:156)
        at sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(JarFileFactory.java:126)
        at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:81)
        at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122)
        at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:152)
        at java.net.URL.openStream(URL.java:1067)
        at java.lang.ClassLoader.getSystemResourceAsStream(ClassLoader.java:1324)
        at java.lang.Class.getResourceAsStream(Class.java:2221)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassClassPath.openClassfile(ClassClassPath.java:80)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:334)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPool.openClassfile(ClassPool.java:613)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile3(CtClassType.java:204)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile2(CtClassType.java:178)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getSuperclass(CtClassType.java:813)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.subclassOf(CtClassType.java:804)
        at com.alibaba.ttl.threadpool.agent.internal.transformlet.impl.TtlExecutorTransformlet.doTransform(TtlExecutorTransformlet.java:73)
        at com.alibaba.ttl.threadpool.agent.TtlTransformer.transform(TtlTransformer.java:58)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
        at java.util.LinkedHashMap$LinkedKeySet.iterator(LinkedHashMap.java:543)
        at java.io.ExpiringCache.cleanup(ExpiringCache.java:119)
        at java.io.ExpiringCache.put(ExpiringCache.java:87)
        at java.io.UnixFileSystem.canonicalize(UnixFileSystem.java:173)
        at java.io.File.getCanonicalPath(File.java:618)
        at java.io.FilePermission$1.run(FilePermission.java:224)
        at java.io.FilePermission$1.run(FilePermission.java:212)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.io.FilePermission.init(FilePermission.java:212)
        at java.io.FilePermission.<init>(FilePermission.java:299)
        at sun.net.www.protocol.file.FileURLConnection.getPermission(FileURLConnection.java:225)
        at java.net.URLClassLoader.getPermissions(URLClassLoader.java:666)
        at java.security.SecureClassLoader.getProtectionDomain(SecureClassLoader.java:206)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext.reset(OutputEventListenerBackedLoggerContext.java:81)
        at org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext.<init>(OutputEventListenerBackedLoggerContext.java:46)
        at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:30)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:27)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
        at org.gradle.internal.concurrent.CompositeStoppable.<clinit>(CompositeStoppable.java:37)
        at org.gradle.internal.service.DefaultServiceRegistry$OwnServices.<init>(DefaultServiceRegistry.java:378)
        at org.gradle.internal.service.DefaultServiceRegistry.<init>(DefaultServiceRegistry.java:101)
        at org.gradle.internal.service.DefaultServiceRegistry.<init>(DefaultServiceRegistry.java:88)
        at org.gradle.internal.logging.services.LoggingServiceRegistry.<init>(LoggingServiceRegistry.java:47)
        at org.gradle.internal.logging.services.LoggingServiceRegistry$CommandLineLogging.<init>(LoggingServiceRegistry.java:157)
        at org.gradle.internal.logging.services.LoggingServiceRegistry$CommandLineLogging.<init>(LoggingServiceRegistry.java:157)
        at org.gradle.internal.logging.services.LoggingServiceRegistry.newEmbeddableLogging(LoggingServiceRegistry.java:101)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:90)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

其他信息

  1. 只在Gradle下出现,使用Maven构建不会有此异常
  2. 修复建议,在JavaAgent的Processor里直接忽略 java.util 包吧,这个包里本来也没有线程池

PS: 这个问题不影响使用,只是运行测试的时候会打印个异常,然后实际结果一切正常;不紧急。

oldratlee commented 3 years ago

非常专业的问题说明(包含复现代码工程) @linfan 👍 ❤️

想进一步挖一下,以更完整分析深入些解决这个问题。 原因如下:

2. 修复建议,在JavaAgent的Processor里直接忽略 java.util 包吧,这个包里本来也没有线程池


@linfan 有空方便一起分析原因以进一步解决吗? 😃

xyc0123456789 commented 2 years ago

window10环境,jvm版本

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

我在cmd中使用

java -Dfile.encoding=utf-8 \
  -Xbootclasspath/a:C:/mvn_repository/com/alibaba/transmittable-thread-local/2.12.1 \
  -javaagent:C:/mvn_repository/com/alibaba/transmittable-thread-local/2.12.1/transmittable-thread-local-2.12.1.jar \
  -jar hello-1.0.0.jar

命令启动jar包也遇到了类似的循环依赖的问题;

变更transmittable-thread-local版本为2.10.2,便不会再命令行遇到这个错误; 在idea中配置2.12.1版本或者2.10.2的上述同样的vm options,也没有遇到循环依赖的错误。

2021-12-13 16:04:00.562 SEVERE [main] TtlTransformer: Fail to transform class java/util/LinkedHashMap$LinkedKeySet, cause: java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeySet
java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeySet
        at java.util.LinkedHashMap.keySet(Unknown Source)
        at java.io.ExpiringCache.cleanup(Unknown Source)
        at java.io.ExpiringCache.get(Unknown Source)
        at java.io.WinNTFileSystem.canonicalize(Unknown Source)
        at java.io.File.getCanonicalPath(Unknown Source)
        at java.io.FilePermission$1.run(Unknown Source)
        at java.io.FilePermission$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.io.FilePermission.init(Unknown Source)
        at java.io.FilePermission.<init>(Unknown Source)
        at sun.net.www.protocol.file.FileURLConnection.getPermission(Unknown Source)
        at sun.net.www.protocol.jar.JarFileFactory.getPermission(Unknown Source)
        at sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(Unknown Source)
        at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
        at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Unknown Source)
        at java.net.URL.openStream(Unknown Source)
        at java.lang.ClassLoader.getSystemResourceAsStream(Unknown Source)
        at java.lang.Class.getResourceAsStream(Unknown Source)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassClassPath.openClassfile(ClassClassPath.java:80)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:334)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPool.openClassfile(ClassPool.java:613)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile3(CtClassType.java:204)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile2(CtClassType.java:178)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getSuperclass(CtClassType.java:813)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.subclassOf(CtClassType.java:804)
        at com.alibaba.ttl.threadpool.agent.internal.transformlet.impl.TtlExecutorTransformlet.doTransform(TtlExecutorTransformlet.java:73)
        at com.alibaba.ttl.threadpool.agent.TtlTransformer.transform(TtlTransformer.java:58)
        at sun.instrument.TransformerManager.transform(Unknown Source)
        at sun.instrument.InstrumentationImpl.transform(Unknown Source)
        at java.util.LinkedHashMap.keySet(Unknown Source)
        at java.io.ExpiringCache.cleanup(Unknown Source)
        at java.io.ExpiringCache.put(Unknown Source)
        at java.io.WinNTFileSystem.canonicalize(Unknown Source)
        at java.io.File.getCanonicalPath(Unknown Source)
        at sun.security.provider.PolicyFile.canonPath(Unknown Source)
        at sun.security.provider.PolicyFile.canonicalizeCodebase(Unknown Source)
        at sun.security.provider.PolicyFile.getCodeSource(Unknown Source)
        at sun.security.provider.PolicyFile.addGrantEntry(Unknown Source)
        at sun.security.provider.PolicyFile.init(Unknown Source)
        at sun.security.provider.PolicyFile.access$400(Unknown Source)
        at sun.security.provider.PolicyFile$3.run(Unknown Source)
        at sun.security.provider.PolicyFile$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.security.provider.PolicyFile.initPolicyFile(Unknown Source)
        at sun.security.provider.PolicyFile.initPolicyFile(Unknown Source)
        at sun.security.provider.PolicyFile.init(Unknown Source)
        at sun.security.provider.PolicyFile.<init>(Unknown Source)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at java.security.Policy.getPolicyNoCheck(Unknown Source)
        at java.security.ProtectionDomain.implies(Unknown Source)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at ch.qos.logback.core.util.Loader$1.run(Loader.java:48)
        at ch.qos.logback.core.util.Loader$1.run(Loader.java:45)
        at java.security.AccessController.doPrivileged(Native Method)
        at ch.qos.logback.core.util.Loader.<clinit>(Loader.java:45)
        at ch.qos.logback.classic.util.ContextInitializer.findURLOfDefaultConfigurationFile(ContextInitializer.java:119)
        at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
        at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
2021-12-13 16:04:00.580 SEVERE [main] TtlTransformer: Fail to transform class java/util/LinkedHashMap$LinkedKeyIterator, cause: java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeyIterator
java.lang.ClassCircularityError: java/util/LinkedHashMap$LinkedKeyIterator
        at java.util.LinkedHashMap$LinkedKeySet.iterator(Unknown Source)
        at java.io.ExpiringCache.cleanup(Unknown Source)
        at java.io.ExpiringCache.get(Unknown Source)
        at java.io.WinNTFileSystem.canonicalize(Unknown Source)
        at java.io.File.getCanonicalPath(Unknown Source)
        at java.io.FilePermission$1.run(Unknown Source)
        at java.io.FilePermission$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.io.FilePermission.init(Unknown Source)
        at java.io.FilePermission.<init>(Unknown Source)
        at sun.net.www.protocol.file.FileURLConnection.getPermission(Unknown Source)
        at sun.net.www.protocol.jar.JarFileFactory.getPermission(Unknown Source)
        at sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(Unknown Source)
        at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
        at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Unknown Source)
        at java.net.URL.openStream(Unknown Source)
        at java.lang.ClassLoader.getSystemResourceAsStream(Unknown Source)
        at java.lang.Class.getResourceAsStream(Unknown Source)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassClassPath.openClassfile(ClassClassPath.java:80)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPoolTail.openClassfile(ClassPoolTail.java:334)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.ClassPool.openClassfile(ClassPool.java:613)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile3(CtClassType.java:204)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getClassFile2(CtClassType.java:178)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.getSuperclass(CtClassType.java:813)
        at com.alibaba.ttl.threadpool.agent.internal.javassist.CtClassType.subclassOf(CtClassType.java:804)
        at com.alibaba.ttl.threadpool.agent.internal.transformlet.impl.TtlExecutorTransformlet.doTransform(TtlExecutorTransformlet.java:73)
        at com.alibaba.ttl.threadpool.agent.TtlTransformer.transform(TtlTransformer.java:58)
        at sun.instrument.TransformerManager.transform(Unknown Source)
        at sun.instrument.InstrumentationImpl.transform(Unknown Source)
        at java.util.LinkedHashMap$LinkedKeySet.iterator(Unknown Source)
        at java.io.ExpiringCache.cleanup(Unknown Source)
        at java.io.ExpiringCache.put(Unknown Source)
        at java.io.WinNTFileSystem.canonicalize(Unknown Source)
        at java.io.File.getCanonicalPath(Unknown Source)
        at sun.security.provider.PolicyFile.canonPath(Unknown Source)
        at sun.security.provider.PolicyFile.canonicalizeCodebase(Unknown Source)
        at sun.security.provider.PolicyFile.getCodeSource(Unknown Source)
        at sun.security.provider.PolicyFile.addGrantEntry(Unknown Source)
        at sun.security.provider.PolicyFile.init(Unknown Source)
        at sun.security.provider.PolicyFile.access$400(Unknown Source)
        at sun.security.provider.PolicyFile$3.run(Unknown Source)
        at sun.security.provider.PolicyFile$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.security.provider.PolicyFile.initPolicyFile(Unknown Source)
        at sun.security.provider.PolicyFile.initPolicyFile(Unknown Source)
        at sun.security.provider.PolicyFile.init(Unknown Source)
        at sun.security.provider.PolicyFile.<init>(Unknown Source)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at java.security.Policy.getPolicyNoCheck(Unknown Source)
        at java.security.ProtectionDomain.implies(Unknown Source)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at ch.qos.logback.core.util.Loader$1.run(Loader.java:48)
        at ch.qos.logback.core.util.Loader$1.run(Loader.java:45)
        at java.security.AccessController.doPrivileged(Native Method)
        at ch.qos.logback.core.util.Loader.<clinit>(Loader.java:45)
        at ch.qos.logback.classic.util.ContextInitializer.findURLOfDefaultConfigurationFile(ContextInitializer.java:119)
        at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:148)
        at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
oldratlee commented 2 years ago

@linfan @xyc0123456789 发布了v2.12.3 https://github.com/alibaba/transmittable-thread-local/releases/tag/v2.12.3

包含这个问题的修复;可以试试是不是解决问题了? ❤️

PS: https://github.com/linfan/transmittable-thread-local-issue-278 在我MAC开发机Java 8 (1.8.0_312)上N次运行,没复现出来 😅 可能和 操作系统WINDOWSJava的小版本有关系。

# My java version
$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment Corretto-8.312.07.1 (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM Corretto-8.312.07.1 (build 25.312-b07, mixed mode)
xyc0123456789 commented 2 years ago

刚刚验证了一下,2.12.3没有再出现前面的循环依赖的问题了。

我注意到在之前的环境下,cmd中使用

java -Dfile.encoding=utf-8 
-Xbootclasspath/a:C:/mvn_repository/com/alibaba/transmittable-thread-local/2.12.1 
-javaagent:C:/mvn_repository/com/alibaba/transmittable-thread-local/2.12.1/transmittable-thread-local-2.12.1.jar 
-jar mdc-ttl-server-1.0-SNAPSHOT.jar

命令启动会出现循环依赖,而

java -Dfile.encoding=utf-8  
-javaagent:C:/mvn_repository/com/alibaba/transmittable-thread-local/2.12.1/transmittable-thread-local-2.12.1.jar 
-jar mdc-ttl-server-1.0-SNAPSHOT.jar

去掉了-Xbootclasspath选项就不会出现循环依赖的错误

oldratlee commented 2 years ago

@xyc0123456789 谢谢你的验证。👍


去掉了-Xbootclasspath选项就不会出现循环依赖的错误

TTLv2.6.0开始,加载TTL Agent时会自动设置TTL Jarboot class path上; 可以不需要为TTL添加-Xbootclasspath JVM参数。 @xyc0123456789

注意:不能修改从Maven库下载的TTL Jar文件名(形如transmittable-thread-local-2.x.y.jar)。 如果修改了,则需要自己手动通过-Xbootclasspath JVM参数来显式配置(就像TTL之前的版本的做法一样)。

更多参见文档

YoungHu commented 1 year ago

@oldratlee 问题修复了,出现问题的根本原因可以分享说明下吗?