alibaba / arthas

Alibaba Java Diagnostic Tool Arthas/Alibaba Java诊断利器Arthas
https://arthas.aliyun.com/
Apache License 2.0
35.7k stars 7.51k forks source link

使用arthas出现异常:com.taobao.arthas.core.command.express.ExpressException: java.lang.NullPointerException: target is null for method getBean #2942

Open Uncle-Xi opened 1 week ago

Uncle-Xi commented 1 week ago

环境信息

重现问题的步骤

1、pom导入依赖

com.taobao.arthas arthas-tunnel-server 4.0.2
    <dependency>
        <groupId>com.taobao.arthas</groupId>
        <artifactId>arthas-spring-boot-starter</artifactId>
        <version>4.0.2</version>
    </dependency>

2、yml配置了 spring: arthas: enabled: true arthas: ip: 0.0.0.0

3、在控台执行命令就报错(arthas idea plugin 拷贝的命令 —— 命令本身没问题)

http://localhost:8563/

期望的结果

What do you expected from the above steps?

正常执行命令

实际运行的结果

实际运行结果,最好有详细的日志,异常栈。尽量贴文本。


2024-11-10 22:06:49 [arthas-command-execute] WARN  c.t.a.c.command.klass100.OgnlCommand -ognl: failed execute express: #springContext=@com.web.toolkit.utils.ApplicationContextHolder@context,#springContext.getBean("authMetadataService").permissionOptions()
com.taobao.arthas.core.command.express.ExpressException: java.lang.NullPointerException: target is null for method getBean
    at com.taobao.arthas.core.command.express.OgnlExpress.get(OgnlExpress.java:39)
    at com.taobao.arthas.core.command.klass100.OgnlCommand.process(OgnlCommand.java:106)
    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:385)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    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.NullPointerException: target is null for method getBean
    at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1620)
    at ognl.ASTMethod.getValueBody(ASTMethod.java:72)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:171)
    at ognl.SimpleNode.getValue(SimpleNode.java:206)
    at ognl.ASTChain.getValueBody(ASTChain.java:128)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:171)
    at ognl.SimpleNode.getValue(SimpleNode.java:206)
    at ognl.ASTSequence.getValueBody(ASTSequence.java:47)
    at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:171)
    at ognl.SimpleNode.getValue(SimpleNode.java:206)
    at ognl.Ognl.getValue(Ognl.java:408)
    at ognl.Ognl.getValue(Ognl.java:480)
    at ognl.Ognl.getValue(Ognl.java:460)
    at com.taobao.arthas.core.command.express.OgnlExpress.get(OgnlExpress.java:36)
    ... 14 common frames omitted
WangJi92 commented 1 week ago

hello, 我这里也测试了一下 ,你可能需要携带 -c classloader hashcode ,Caused by: java.lang.NullPointerException: target is null for method getBean ,获取静态的spring context 为null

@Uncle-Xi

[arthas@22736]$ ognl -x 3 '#springContext=@com.wangji92.arthas.plugin.demo.common.ApplicationContextProvider@context,#springContext.getBean("commonController").innerAnonymousClass()'
Failed to execute ognl, exception message: java.lang.NullPointerException: target is null for method getBean, please check $HOME/logs/arthas/arthas.log for more details.
[arthas@22736]$ ognl -x 3 '#springContext=@com.wangji92.arthas.plugin.demo.common.ApplicationContextProvider@context,#springContext.getBean("commonController").innerAnonymousClass()' -c 17c2f048
@String[ok]
WangJi92 commented 1 week ago

不过推荐你换个命令 ,这个命令更加灵活 https://arthas.aliyun.com/doc/vmtool.html ,不需要配置spring context ,任何项目都可以 image

Uncle-Xi commented 1 week ago

好的,多谢 多谢

xizongren @.***

 

------------------ 原始邮件 ------------------ 发件人: "alibaba/arthas" @.>; 发送时间: 2024年11月11日(星期一) 上午9:35 @.>; @.**@.>; 主题: Re: [alibaba/arthas] 使用arthas出现异常:com.taobao.arthas.core.command.express.ExpressException: java.lang.NullPointerException: target is null for method getBean (Issue #2942)

不过推荐你换个命令 ,这个命令更加灵活 https://arthas.aliyun.com/doc/vmtool.html ,不需要配置spring context ,任何项目都可以 image.png (view on web)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>