5
环境信息
arthas-boot.jar
或者as.sh
的版本:- Arthas 版本: 3.5.4
- 操作系统版本: mac os BigSur 11.2.3
- 目标进程的JVM版本: 1.8.0_261
- 执行
arthas-boot
的版本: xxx
被增强的目标方法
int id = 1;
@RequestMapping("throwable")
public String testThrowable() {
id++;
if (id % 2 == 0) {
throw new IllegalArgumentException("illegal argument");
} else {
return "normal";
}
}
byte-buddy增强的逻辑
public class ThrowableInterceptor {
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void onMethodExit(@Advice.Thrown Throwable throwable) throws Throwable {
if (throwable != null) {
System.out.println("Inner:" + throwable.getMessage());
}
}
}
期望的结果
使用byte-buddy导出增强后的方法是
@RequestMapping({"throwable"})
public String testThrowable() {
TtlTestController var1 = this;
Throwable var2;
String var5;
label29: {
String var10000;
try {
++var1.id;
if (var1.id % 2 == 0) {
throw new IllegalArgumentException("illegal argument");
}
var10000 = "normal";
} catch (Throwable var4) {
var2 = var4;
var5 = null;
break label29;
}
var5 = var10000;
var2 = null;
}
if (var2 != null) {
System.out.println("Inner:" + var2.getMessage());
}
if (var2 != null) {
throw var2;
} else {
return var5;
}
}
static {
ClassLoader.getSystemClassLoader().loadClass("net.bytebuddy.dynamic.Nexus").getMethod("initialize", Class.class, Integer.TYPE).invoke((Object)null, TtlTestController.class, 1749305575);
}
实际运行的结果
通过jad查看当前类的源码如下,没有正确的展示出增强的代码
@RequestMapping(value={"throwable"})
public String testThrowable() {
Object object = this;
try {
/*65*/ ++((TtlTestController)object).id;
/*66*/ if (((TtlTestController)object).id % 2 == 0) {
throw new IllegalArgumentException("illegal argument");
}
/*69*/ object = "normal";
return object;
}
finally {
Object var2_2 = null;
}
}
static {
ClassLoader.getSystemClassLoader().loadClass("net.bytebuddy.dynamic.Nexus").getMethod("initialize", Class.class, Integer.TYPE).invoke(null, TtlTestController.class, 158597040);
}
}