arthas 参数由long替换为Long,redefine后报NoSuchMethodError

6fe3ivhb  于 2021-11-28  发布在  Java
关注(0)|答案(5)|浏览(539)
  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • arthas-boot.jar 或者 as.sh 的版本:3.1.4
  • Arthas 版本: 3.1.4
  • 操作系统版本: macOS 10.15(并且在Linux上能重现)
  • 目标进程的JVM版本: 1.8.0_222
  • 执行arthas-boot的版本: 1.8.0_222

重现问题的步骤

  1. 用旧代码启动进程
    旧代码
public class Main {
    private static void test(long val) {
        System.out.println(val);
    }

    public static void main(String[] args) throws InterruptedException {
        while (true) {
            Thread.sleep(1000);
            test(1L);
        }
    }
}
  1. 编译新代码,得到Main.class
    新代码
public class Main {
    private static void test(Long val) {
        System.out.println(val);
    }

    public static void main(String[] args) throws InterruptedException {
        while (true) {
            Thread.sleep(1000);
            test(1L);
        }
    }
}
  1. 启动arthas,执行命令redefine /path/to/Main.class

期望的结果

redefine error! java.lang.UnsupportedOperationException: class redefinition failed: attempted to delete a method

  • 这也是java11下的表现*

实际运行的结果

  • java8下*

redefine success, size: 1

说明重定义成功,但是主进程报错:

Exception in thread "main" java.lang.NoSuchMethodError: Main.test(J)V
	at Main.main(Main.java:9)
6jygbczu

6jygbczu1#

将参数从int换成long,也会触发同样的错误

qv7cva1a

qv7cva1a2#

The redefinition must not add, remove or rename fields or methods, change the
signatures of methods, or change inheritance.

rmbxnbpk

rmbxnbpk3#

That means redefining should failed, not redefining successfully, and the program cannot running.

It looks like a JDK's bug.

qqrboqgw

qqrboqgw4#

redefine 过程中无法检测语法

kqqjbcuj

kqqjbcuj5#

"Exception in thread "main" java.lang.NoSuchMethodError" 异常应该跟jvm在解释执行选取方法过程有关。

相关问题