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

watch等命令 retransformClasses 执行失败 java.lang.InternalError #730

Open
hengyunabc opened this issue Jun 5, 2019 · 5 comments
Open

Comments

@hengyunabc
Copy link
Collaborator

执行:

$ watch watch org.apache.logging.log4j.core.filter.AbstractFilterable isFiltered "{params,returnObj}"
Error during processing the command: null

查看~/logs/arthas/arthas.log:

java.lang.InternalError: null
        at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method) ~[na:1.8.0_102]
        at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144) ~[na:1.8.0_102]
        at com.taobao.arthas.core.advisor.Enhancer.enhance(Enhancer.java:304) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.enhance(EnhancerCommand.java:111) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.process(EnhancerCommand.java:66) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:370) ~[arthas-core.jar:3.1.1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_102]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_102]
        at java.lang.Thread.run(Thread.java:766) [na:1.8.0_102]

用sc命令来查找这个类,发现有非常多的实现类:

$ sc watch org.apache.logging.log4j.core.filter.AbstractFilterable
watch org.apache.logging.log4j.core.appender.AbstractAppender   
watch org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender
watch org.apache.logging.log4j.core.appender.AbstractWriterAppender
watch org.apache.logging.log4j.core.appender.AsyncAppender
watch org.apache.logging.log4j.core.appender.ConsoleAppender
watch org.apache.logging.log4j.core.appender.CountingNoOpAppender
watch org.apache.logging.log4j.core.appender.FailoverAppender
watch org.apache.logging.log4j.core.appender.FileAppender
watch org.apache.logging.log4j.core.appender.MemoryMappedFileAppender
watch org.apache.logging.log4j.core.appender.NullAppender
watch org.apache.logging.log4j.core.appender.OutputStreamAppender
watch org.apache.logging.log4j.core.appender.RandomAccessFileAppender
watch org.apache.logging.log4j.core.appender.RollingFileAppender
watch org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender
watch org.apache.logging.log4j.core.appender.ScriptAppenderSelector
watch org.apache.logging.log4j.core.appender.SmtpAppender
watch org.apache.logging.log4j.core.appender.SocketAppender
watch org.apache.logging.log4j.core.appender.SyslogAppender
watch org.apache.logging.log4j.core.appender.WriterAppender
watch org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender
watch org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender
watch org.apache.logging.log4j.core.appender.db.jpa.JpaAppender
watch org.apache.logging.log4j.core.appender.mom.JmsAppender
watch org.apache.logging.log4j.core.appender.mom.jeromq.JeroMqAppender
watch org.apache.logging.log4j.core.appender.mom.kafka.KafkaAppender
watch org.apache.logging.log4j.core.appender.rewrite.RewriteAppender
watch org.apache.logging.log4j.core.appender.routing.RoutingAppender
watch org.apache.logging.log4j.core.async.AsyncLoggerConfig
watch org.apache.logging.log4j.core.async.AsyncLoggerConfig$RootLogger
watch org.apache.logging.log4j.core.config.AbstractConfiguration
watch org.apache.logging.log4j.core.config.AppenderControl
watch org.apache.logging.log4j.core.config.DefaultConfiguration
watch org.apache.logging.log4j.core.config.LoggerConfig
watch org.apache.logging.log4j.core.config.LoggerConfig$RootLogger
watch org.apache.logging.log4j.core.config.NullConfiguration
watch org.apache.logging.log4j.core.config.xml.XmlConfiguration
watch org.apache.logging.log4j.core.filter.AbstractFilterable

查看代码,发现执行的是批量增强:

//com.taobao.arthas.core.advisor.Enhancer
        // 构建增强器
        final Enhancer enhancer = new Enhancer(adviceId, isTracing, skipJDKTrace, enhanceClassSet, methodNameMatcher, affect);
        try {
            inst.addTransformer(enhancer, true);

            // 批量增强
            if (GlobalOptions.isBatchReTransform) {
                final int size = enhanceClassSet.size();
                final Class<?>[] classArray = new Class<?>[size];
                arraycopy(enhanceClassSet.toArray(), 0, classArray, 0, size);
                if (classArray.length > 0) {
                    inst.retransformClasses(classArray);
                    logger.info("Success to batch transform classes: " + Arrays.toString(classArray));
                }
            } else {
                // for each 增强
                for (Class<?> clazz : enhanceClassSet) {
                    try {
                        inst.retransformClasses(clazz);
                        logger.info("Success to transform class: " + clazz);
                    } catch (Throwable t) {
                        logger.warn("retransform {} failed.", clazz, t);
                        if (t instanceof UnmodifiableClassException) {
                            throw (UnmodifiableClassException) t;
                        } else if (t instanceof RuntimeException) {
                            throw (RuntimeException) t;
                        } else {
                            throw new RuntimeException(t);
                        }
                    }
                }
            }
        } finally {
            inst.removeTransformer(enhancer);
        }

试下把批量增强关掉:

$ options batch-re-transform false

再来执行:

$ watch org.apache.logging.log4j.core.filter.AbstractFilterable isFiltered "{params,returnObj}"
Error during processing the command: java.lang.InternalError

再查看日志,打印出了具体的类org.apache.logging.log4j.core.appender.mom.JmsAppender

01 2019-06-05 19:48:51.500 WARN [as-command-execute-daemon:arthas] [] [] [] retransform class org.apache.logging.log4j.core.appender.mom.JmsAppender failed.
java.lang.InternalError: null
        at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method) ~[na:1.8.0_102]
        at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144) ~[na:1.8.0_102]
        at com.taobao.arthas.core.advisor.Enhancer.enhance(Enhancer.java:311) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.enhance(EnhancerCommand.java:111) [arthas-core.jar:3.1.1]

再用jad来查看下源代码:

$ jad org.apache.logging.log4j.core.appender.mom.JmsAppender

ClassLoader:
+-org.springframework.boot.loader.LaunchedURLClassLoader@16267862
  +-sun.misc.Launcher$AppClassLoader@18b4aac2
    +-sun.misc.Launcher$ExtClassLoader@3ecd23d9

Location:
file:/home/admin/xxx/target/exploded/BOOT-INF/lib/log4j-core-2.8.2.jar!/

/*
 * Decompiled with CFR 0_132.
 *
 * Could not load the following classes:
 *  javax.jms.JMSException
 *  javax.jms.Message
 *  javax.jms.MessageProducer
 *  org.apache.logging.log4j.Logger
 *  org.apache.logging.log4j.core.Filter
 *  org.apache.logging.log4j.core.Layout
 *  org.apache.logging.log4j.core.LogEvent
 *  org.apache.logging.log4j.core.appender.AbstractAppender
 *  org.apache.logging.log4j.core.appender.AppenderLoggingException
 *  org.apache.logging.log4j.core.appender.mom.JmsAppender$1
 *  org.apache.logging.log4j.core.appender.mom.JmsAppender$Builder
 *  org.apache.logging.log4j.core.appender.mom.JmsManager
 *  org.apache.logging.log4j.core.config.plugins.Plugin
 *  org.apache.logging.log4j.core.config.plugins.PluginAliases
 *  org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory
 */
package org.apache.logging.log4j.core.appender.mom;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.appender.AppenderLoggingException;
import org.apache.logging.log4j.core.appender.mom.JmsAppender;
import org.apache.logging.log4j.core.appender.mom.JmsManager;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAliases;
import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;

@Plugin(name="JMS", category="Core", elementType="appender", printObject=true)
@PluginAliases(value={"JMSQueue", "JMSTopic"})
public class JmsAppender
extends AbstractAppender {
    private final JmsManager manager;
    private final MessageProducer producer;
    private static transient /* synthetic */ boolean[] $jacocoData;

    protected JmsAppender(String string, Filter filter, Layout<? extends Serializable> layout, boolean bl, JmsManager jmsManager) throws JMSException {
        void layout2;
        void filter2;
        void ignoreExceptions;
        void name;
        void manager;
        boolean[] arrbl = JmsAppender.$jacocoInit();
        super((String)name, (Filter)filter2, (Layout)layout2, (boolean)ignoreExceptions);
        this.manager = manager;
        arrbl[0] = true;
        this.producer = this.manager.createMessageProducer();
        arrbl[1] = true;
    }

    public void append(LogEvent logEvent) {
        boolean[] arrbl = JmsAppender.$jacocoInit();
        try {
            void event;
            void message;
            Message message2 = this.manager.createMessage(this.getLayout().toSerializable((LogEvent)event));
            arrbl[2] = true;
            message.setJMSTimestamp(event.getTimeMillis());
            arrbl[3] = true;
            this.producer.send((Message)message);
        }
        catch (JMSException message) {
            void e;
            arrbl[4] = true;
            arrbl[5] = true;
            throw new AppenderLoggingException((Throwable)e);
        }
        arrbl[6] = true;
    }

    public boolean stop(long l, TimeUnit timeUnit) {
        void timeout;
        void timeUnit2;
        boolean[] arrbl = JmsAppender.$jacocoInit();
        this.setStopping();
        arrbl[7] = true;
        boolean bl = super.stop((long)timeout, (TimeUnit)timeUnit2, false);
        arrbl[8] = true;
        arrbl[9] = true;
        this.setStopped();
        arrbl[10] = true;
        return stopped &= this.manager.stop((long)timeout, (TimeUnit)timeUnit2);
    }

    @PluginBuilderFactory
    public static Builder newBuilder() {
        boolean[] arrbl = JmsAppender.$jacocoInit();
        arrbl[11] = true;
        return new Builder(null);
    }

    static /* synthetic */ Logger access$100() {
        boolean[] arrbl = JmsAppender.$jacocoInit();
        arrbl[12] = true;
        return LOGGER;
    }

    private static /* synthetic */ boolean[] $jacocoInit() {
        boolean[] arrbl = $jacocoData;
        if (arrbl == null) {
            Object[] arrobject = new Object[]{-6190699681961106805L, "org/apache/logging/log4j/core/appender/mom/JmsAppender", 13};
            UnknownError.$jacocoAccess.equals(arrobject);
            arrbl = $jacocoData = (boolean[])arrobject[0];
        }
        return arrbl;
    }
}

发现是被jacoco处理过的

@hengyunabc
Copy link
Collaborator Author

重新测试了下,发现不是jacoco引起的:

import java.io.IOException;

public class TestJmsAppender {
	public static void main(String[] args) throws IOException {
		System.out.println(org.apache.logging.log4j.core.appender.mom.JmsAppender.class);
		System.in.read();
	}
}

启动:

java -cp /Users/hengyunabc/.m2/repository/org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.jar:. TestJmsAppender

用arthas执行:

watch org.apache.logging.log4j.core.appender.mom.JmsAppender stop target

错误是:

java.lang.InternalError: null
        at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method) ~[na:1.8.0_112]
        at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144) ~[na:1.8.0_112]
        at com.taobao.arthas.core.advisor.Enhancer.enhance(Enhancer.java:304) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.enhance(EnhancerCommand.java:111) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.process(EnhancerCommand.java:66) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108) ~[arthas-core.jar:3.1.1]
        at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:370) ~[arthas-core.jar:3.1.1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_112]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_112]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_112]

可能是JVM本身的bug,找到两个相关的issue:

@hengyunabc
Copy link
Collaborator Author

hengyunabc commented Jun 6, 2019

2.8.2版本

出错:

/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java -cp /Users/hengyunabc/.m2/repository/org/apache/logging/log4j/log4j-core/2.8.2/log4j-core-2.8.2.jar:. TestJmsAppender

出错:

/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java -cp /Users/hengyunabc/.m2/repository/org/apache/logging/log4j/log4j-core/2.8.2/log4j-core-2.8.2.jar:/Users/hengyunabc/.m2/repository/org/apache/logging/log4j/log4j-api/2.8.2/log4j-api-2.8.2.jar:. TestJmsAppender

2.11.2版本

出错:

/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java -cp /Users/hengyunabc/.m2/repository/org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.jar:. TestJmsAppender

正常:

/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java -cp /Users/hengyunabc/.m2/repository/org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.jar:/Users/hengyunabc/.m2/repository/org/apache/logging/log4j/log4j-api/2.11.2/log4j-api-2.11.2.jar:. TestJmsAppender

在执行watch之前,classloader加载到的类是:

$ classloader -c 4e25154f -a
 hash:1311053135, sun.misc.Launcher$AppClassLoader@4e25154f
 TestJmsAppender
 com.taobao.arthas.agent.AgentBootstrap
 com.taobao.arthas.agent.AgentBootstrap$1
 com.taobao.arthas.agent.ArthasClassloader
 org.apache.logging.log4j.core.AbstractLifeCycle
 org.apache.logging.log4j.core.Appender
 org.apache.logging.log4j.core.LifeCycle
 org.apache.logging.log4j.core.LifeCycle2
 org.apache.logging.log4j.core.appender.AbstractAppender
 org.apache.logging.log4j.core.appender.mom.JmsAppender
 org.apache.logging.log4j.core.filter.AbstractFilterable
 org.apache.logging.log4j.core.filter.Filterable

在watch之后,加载到的类是:

 $ classloader -c 4e25154f -a
 hash:1311053135, sun.misc.Launcher$AppClassLoader@4e25154f
 TestJmsAppender
 com.taobao.arthas.agent.AgentBootstrap
 com.taobao.arthas.agent.AgentBootstrap$1
 com.taobao.arthas.agent.ArthasClassloader
 org.apache.logging.log4j.Logger
 org.apache.logging.log4j.core.AbstractLifeCycle
 org.apache.logging.log4j.core.Appender
 org.apache.logging.log4j.core.ErrorHandler
 org.apache.logging.log4j.core.Filter
 org.apache.logging.log4j.core.LifeCycle
 org.apache.logging.log4j.core.LifeCycle2
 org.apache.logging.log4j.core.appender.AbstractAppender
 org.apache.logging.log4j.core.appender.mom.JmsAppender
 org.apache.logging.log4j.core.filter.AbstractFilterable
 org.apache.logging.log4j.core.filter.Filterable

发现watch前后,多加载了三个类 org.apache.logging.log4j.Logger , org.apache.logging.log4j.core.ErrorHandler , org.apache.logging.log4j.core.Filter 。

其中 org.apache.logging.log4j.Logger 是在 log4j-api 里的。

@hengyunabc hengyunabc changed the title jacoco agent导致的 watch等命令执行失败 java.lang.InternalError watch等命令 retransformClasses 执行失败 java.lang.InternalError Jun 6, 2019
@hengyunabc
Copy link
Collaborator Author

org.apache.logging.log4j.core.appender.mom.JmsAppender 本身依赖一些JMS的类,在应用的classpath里是没有的。

疑问是:

  • jdk在retransformClasses 时,会触发其它类的加载不?是否加载类失败的异常被吃掉了
  • 具体什么原因导致 2.8.2版本 失败,2.11.2版本可以执行?

@kylixs
Copy link
Contributor

kylixs commented May 9, 2020

arthas-mybatis-demo中遇到这个问题,可能是依赖的class not found导致的。
1) trace org.apache.ibatis.logging.Log *

[arthas@35581]$ trace org.apache.ibatis.logging.Log *
Error during processing the command: null
2020-05-09 11:14:53 [as-command-execute-daemon] ERROR c.t.a.c.s.system.impl.ProcessImpl -Error during processing the command:
java.lang.InternalError: null
        at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
        at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
        at com.taobao.arthas.core.advisor.Enhancer.enhance(Enhancer.java:303)
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.enhance(EnhancerCommand.java:113)
        at com.taobao.arthas.core.command.monitor200.EnhancerCommand.process(EnhancerCommand.java:68)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
        at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:383)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
  1. sm org.apache.ibatis.logging.Log *
[arthas@35581]$ sm org.apache.ibatis.logging.Log *
Error during processing the command: org/apache/log4j/Priority

调试发现处理 org.apache.ibatis.logging.log4j.Log4jImpl 这类就会失败抛出异常:

2020-05-09 11:14:43 [as-command-execute-daemon] ERROR c.t.a.c.s.system.impl.ProcessImpl -Error during processing the command:
java.lang.NoClassDefFoundError: org/apache/log4j/Priority
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
        at java.lang.Class.getDeclaredConstructors(Class.java:2020)
        at com.taobao.arthas.core.command.klass100.SearchMethodCommand.process(SearchMethodCommand.java:92)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.process(AnnotatedCommandImpl.java:82)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl.access$100(AnnotatedCommandImpl.java:18)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:111)
        at com.taobao.arthas.core.shell.command.impl.AnnotatedCommandImpl$ProcessHandler.handle(AnnotatedCommandImpl.java:108)
        at com.taobao.arthas.core.shell.system.impl.ProcessImpl$CommandProcessTask.run(ProcessImpl.java:383)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Priority
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 12 common frames omitted
  1. jad org.apache.ibatis.logging.log4j.Log4jImpl
    提示加载org.apache.log4j的一些类失败
/*
 * Decompiled with CFR.
 * 
 * Could not load the following classes:
 *  org.apache.ibatis.logging.Log
 *  org.apache.log4j.Level
 *  org.apache.log4j.Logger
 *  org.apache.log4j.Priority
 */
package org.apache.ibatis.logging.log4j;

import org.apache.ibatis.logging.Log;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;

public class Log4jImpl
implements Log {
    private static final String FQCN = Log4jImpl.class.getName();
    private final Logger log;

4)查看org.apache.log4j.Priority

[arthas@35581]$ sc org.apache.log4j.Priority
Affect(row-cnt:0) cost in 5 ms.
[arthas@35581]$ sm org.apache.log4j.Priority *
Affect(row-cnt:0) cost in 3 ms.
  1. trace org.apache.ibatis.logging.log4j.Log4jImpl *
[arthas@35581]$ trace org.apache.ibatis.logging.log4j.Log4jImpl *
Error during processing the command: null

trace 这个Log4jImpl,日志错误和上面trace 接口的一样: java.lang.InternalError: null。
到这里可以得出结论,如果某个类所依赖的其它类加载失败,会导致增强失败,抛出异常: java.lang.InternalError: null

@kylixs
Copy link
Contributor

kylixs commented May 9, 2020

org.apache.logging.log4j.core.appender.mom.JmsAppender 本身依赖一些JMS的类,在应用的classpath里是没有的。

疑问是:

  • jdk在retransformClasses 时,会触发其它类的加载不?是否加载类失败的异常被吃掉了
  • 具体什么原因导致 2.8.2版本 失败,2.11.2版本可以执行?
  1. retransformClasses 会触发加载类,但不会抛出ClassNotFound错误,可能初始化方式不同。如果使用sm xxx ,则会提示ClassNotFound错误。
  2. AbstractFilterable是一个抽象类
    public abstract class AbstractFilterable extends AbstractLifeCycle implements Filterable {
    推测 2.8.2 和 2.11.2的依赖项有所不同,其中某个子类缺少依赖,导致处理这个子类时失败。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants