AIDE BUG 内部类的外部类实例赋值与super()竞争
aide吧
全部回复
仅看楼主
level 10
下面代码无论是Javac还是ecj都不会出错
到AIDE会导致NullPointerException
public class Test {
public static void main(String[] args){
new Test();
}
public Test(){
new 子类();
}
public String getSimpleName(){
return this.getClass().getSimpleName();
}
public class 子类 extends 父类 {
public 子类(){
super();
}
@Override
public String getTestSimpleName(){
return Test.this.getSimpleName();
}
}
public abstract class 父类{
public 父类(){
System.out.println( getTestSimpleName() );
}
public abstract String getTestSimpleName();
}
}
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String Test.getSimpleName()' on a null object reference
at Test$子类.getTestSimpleName(Test.java:20)
at Test$父类.<init>(Test.java:25)
at Test$子类.<init>(Test.java:16)
at Test.<init>(Test.java:9)
at Test.main(Test.java:6)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.aide.ui.build.java.j.run(SourceFile:1)
at java.lang.Thread.run(Thread.java:818)
2019年12月31日 15点12分 1
level 5
我太菜了都不知到妮在说什么
2020年01月01日 10点01分 3
非静态内部类会在编译时自动增加构造函数 参数为外部类即 public 子类(Test test){ } 还会增加一个私有final字段 Test this$0 这是非静态内部类可以使用Test.this的原因 但AIDE 的this$0的赋值在super()方法之后
2020年01月01日 11点01分
父类的构造器 会执行子类的getSimpleName方法 但getSimpleName方法内的Test.this实例是 private final Test this$0;而this$0的赋值在super之后 导致this$0的未赋值便使用导致null javac编译就在之前赋值
2020年01月01日 11点01分
level 10
public class Test$子类 extends 父类 {
private final Test this$0;
public Test$子类(Test test) {
super(test);
this.this$0 = test;
}
static Test access$0(Test$子类 test$子类) {
return test$子类.this$0;
}
@Override
public String getTestSimpleName() {
return this.this$0.getSimpleName();
}
}
2020年01月01日 11点01分 4
level 10
这个是Test$子类.dex反编译后的代码, 父类的构造器会调用 getSimpleName();而this$0的没有赋值
然后就(ー_ー)!!
2020年01月01日 11点01分 5
1