我在SO上看到了这个问题,现在我正在尝试编译被接受的答案中的代码。不幸的是,在代码的这部分我一直收到IllegalStateException:
BasicInterpreter basic = new BasicInterpreter() {
@Override public BasicValue newValue(Type type) {
return type!=null && (type.getSort()==Type.OBJECT || type.getSort()==Type.ARRAY)?
new BasicValue(type): super.newValue(type);
}
@Override public BasicValue merge(BasicValue a, BasicValue b) {
if(a.equals(b)) return a;
if(a.isReference() && b.isReference())
// this is the place to consider the actual type hierarchy if you want
return BasicValue.REFERENCE_VALUE;
return BasicValue.UNINITIALIZED_VALUE;
}
};
使用堆栈跟踪:
Exception in thread "main" java.lang.IllegalStateException
at org.objectweb.asm.tree.analysis.BasicInterpreter.<init>(BasicInterpreter.java:66)
at ConstantTracker$1.<init>(ConstantTracker.java:48)
at ConstantTracker.<init>(ConstantTracker.java:48)
at HelloWorld.analyze(HelloWorld.java:37)
at HelloWorld.main(HelloWorld.java:28)
异常在BasicInterpreter类中被触发:
public BasicInterpreter() {
super(/* latest api = */ ASM8);
if (getClass() != BasicInterpreter.class) {
throw new IllegalStateException(); // at this line
}
}
我尝试继承BasicInterpreter,但是我一直收到相同的异常。
class BasicInterpreterLocal extends BasicInterpreter{} // Throws an IllegalStateException
我尝试过使用asm 7.*,8.**,9.0,但都没有成功。
那么问题出在哪里呢?我找不到它。