[alibaba/arthas]watch 时ognl报NoSuchFieldException

2025-11-12 781 views
8
环境信息
  • arthas-boot.jar 或者 as.sh 的版本: 3.6.3
  • Arthas 版本: 3.6.3
  • 操作系统版本: Linux 4.18.0
  • 目标进程的JVM版本: openjdk 1.8
  • 执行arthas-boot的版本: 3.6.3
重现问题的步骤
[arthas@258677]$ watch -n 1 org.springframework.web.servlet.FrameworkServlet service '#hs=target.handlerMappings,
> #hs.{
>     #hsi=#this,
>     #cn=#hsi.getClass().getName(),
>     (#cn.endsWith("RequestMappingHandlerMapping") || #cn.endsWith("ControllerEndpointHandlerMapping") || #cn.endsWith("WebMvcEndpointHandlerMapping")) ? (#hsi.mappingRegistry.registry.{
>         #om = #this,
>         #om.mapping.patternsCondition != null && (#pattern = #om.mapping.patternsCondition.patterns),
>         #om.mapping.pathPatternsCondition != null && (#pattern = #om.mapping.pathPatternsCondition.patterns),
>         #mtd=#om.mapping.methodsCondition.methods.toString()
>     }) : ""
> }'
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 264 ms, listenerId: 91
watch failed, condition is: null, express is: #hs=target.handlerMappings,
#hs.{
    #hsi=#this,
    #cn=#hsi.getClass().getName(),
    (#cn.endsWith("RequestMappingHandlerMapping") || #cn.endsWith("ControllerEndpointHandlerMapping") || #cn.endsWith("WebMvcEndpointHandlerMapping")) ? (#hsi.mappingRegistry.registry.{
        #om = #this,
        #om.mapping.patternsCondition != null && (#pattern = #om.mapping.patternsCondition.patterns),
        #om.mapping.pathPatternsCondition != null && (#pattern = #om.mapping.pathPatternsCondition.patterns),
        #mtd=#om.mapping.methodsCondition.methods.toString()
    }) : ""
}, ognl.OgnlException: registry [java.lang.NoSuchFieldException: registry], visit /home/admin/logs/arthas/arthas.log for more details.
[arthas@258677]$ version
3.6.3
期望的结果

调试了看是有registry这个Field的,但是报错了。

实际运行的结果

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

watch failed, condition is: null, express is: #hs=target.handlerMappings,
#hs.{
    #hsi=#this,
    #cn=#hsi.getClass().getName(),
    (#cn.endsWith("RequestMappingHandlerMapping") || #cn.endsWith("ControllerEndpointHandlerMapping") || #cn.endsWith("WebMvcEndpointHandlerMapping")) ? (#hsi.mappingRegistry.registry.{
        #om = #this,
        #om.mapping.patternsCondition != null && (#pattern = #om.mapping.patternsCondition.patterns),
        #om.mapping.pathPatternsCondition != null && (#pattern = #om.mapping.pathPatternsCondition.patterns),
        #mtd=#om.mapping.methodsCondition.methods.toString()
    }) : ""
}, ognl.OgnlException: registry [java.lang.NoSuchFieldException: registry], visit /home/admin/logs/arthas/arthas.log for more details.

调试看报错是:

回答

6

这个可能是cglib的类,因为ide可能会做了优化,所以看不出来。 可以试下把对象的类名打印出来。 cglib生成的类 field是空的。 cglib生成类里有一个字段,是真正的原始object,需要找到再取field。

9

这应该不是cglib的,是取的抽象类里的内部类的private final字段,看最后一张图的调试结果显示没有过反射时的AccessibleObject.checkAccess()导致抛异常了。