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

执行OGNL列表解析时,#this设置为了Advice而不是实际值 #2836

Open
1 task done
fzhyzamt opened this issue May 15, 2024 · 0 comments
Open
1 task done

Comments

@fzhyzamt
Copy link

  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • arthas-boot.jar 或者 as.sh 的版本: 3.7.2
  • Arthas 版本: 3.7.2
  • 操作系统版本: windows11 22H2 22621.3447
  • 目标进程的JVM版本: 17.0.6
  • 执行arthas-boot的版本: 17.0.6

重现问题的步骤

  1. 设置一个类型为List<String[]>的变量
public class Main {
    private final List<String[]> list;
    public Main() {
        list = new java.util.ArrayList<>();
        list.add(new String[]{"a", "b", "c"});
        list.add(new String[]{"d", "e", "f"});
        list.add(new String[]{"g", "h", "i"});
    }
}
  1. 使用tt指令捕获一次调用
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        while (true) {
            main.test();
        }
    }
    private void test() throws InterruptedException {
        TimeUnit.SECONDS.sleep(1);
    }
[arthas@18504]$ tt -t -n 1 org.example.Main test
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 83 ms, listenerId: 1
 INDEX      TIMESTAMP                   COST(ms)      IS-RET      IS-EXP     OBJECT               CLASS                                     METHOD                                   
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
 1000       2024-05-15 10:12:04         3007.873      true        false      0x6b884d57           Main                                      test
Command execution times exceed limit: 1, so command will exit. You can set it with -n option.
[arthas@18504]$ tt -i 1000 -w 'target.list.{#this}'
@ArrayList[
    @String[][isEmpty=false;size=3],
    @String[][isEmpty=false;size=3],
    @String[][isEmpty=false;size=3],
]
[arthas@18504]$ tt -i 1000 -w 'target.list.{[0]}'
@ArrayList[
    @String[a],
    @String[d],
    @String[g],
]
[arthas@18504]$ tt -i 1000 -w 'target.list' -x 2
@ArrayList[
    @String[][
        @String[a],
        @String[b],
        @String[c],
    ],
    @String[][
        @String[d],
        @String[e],
        @String[f],
    ],
    @String[][
        @String[g],
        @String[h],
        @String[i],
    ],
]
  1. 使用tt指令执行OGNL,尝试将String[]转换为List或者其他类型,但只能得到一个Advice
[arthas@18504]$ tt -i 1000 -w 'target.list.{@java.util.Arrays@asList(#this)}' -x 2
@ArrayList[
    @ArrayList[
        @Advice[com.taobao.arthas.core.advisor.Advice@19e97882],
    ],
    @ArrayList[
        @Advice[com.taobao.arthas.core.advisor.Advice@19e97882],
    ],
    @ArrayList[
        @Advice[com.taobao.arthas.core.advisor.Advice@19e97882],
    ],
]
[arthas@18504]$ tt -i 1000 -w 'target.list.{@java.util.Arrays@toString(#this)}'
@ArrayList[
    @String[[com.taobao.arthas.core.advisor.Advice@19e97882]],
    @String[[com.taobao.arthas.core.advisor.Advice@19e97882]],
    @String[[com.taobao.arthas.core.advisor.Advice@19e97882]],
]

期望的结果

我希望在循环时,#this代表的是我循环得到的数组,以便我后续进行其他处理,但实际却是Advice实例。

最初遇到这个问题的情况

最初遇到这个问题,是因为项目使用了多个配置文件互相引用,我想要将spring运行时的所有变量打印出来以用来对比配置改动。
参考 #482 拿到了context,但在尝试将List<String[]>设置到单层List时遇到了这个问题。

   tt -i 1000 -w '#result=new java.util.ArrayList(), #env=target.getApplicationContext().getEnvironment(), #list=(#env.getPropertySources().iterator()).{ #this instanceof org.springframework.core.env.PropertySource && #this instanceof org.springframework.core.env.EnumerablePropertySource && #this.getName().contains(".yaml") ? #this.getPropertyNames() : null}.{? #this != null && #this.length > 0}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant