ASM BasicInterpreter 非法状态异常
ASM BasicInterpreter IllegalStateException
我在 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.<init>(ConstantTracker.java:48)
at ConstantTracker.<init>(ConstantTracker.java:48)
at HelloWorld.analyze(HelloWorld.java:37)
at HelloWorld.main(HelloWorld.java:28)
在 BasicInterpreter class:
此处引发异常
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 尝试过,但没有任何效果。
那么问题是什么?。我没找到。
如 中所述,子类应使用接受库版本号的构造函数来确定 ASM 库的兼容级别。代码最初使用的 ASM 库版本 5 似乎没有检查此要求。但是您正在使用强制执行此规则的库的较新版本(显然是 8)。
将代码更改为
BasicInterpreter basic = new BasicInterpreter(Opcodes.ASM5) { // <- the crucial point
@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;
}
};
解决这个问题。我也会更新另一个答案。
我在 SO 上看到了这个
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.<init>(ConstantTracker.java:48)
at ConstantTracker.<init>(ConstantTracker.java:48)
at HelloWorld.analyze(HelloWorld.java:37)
at HelloWorld.main(HelloWorld.java:28)
在 BasicInterpreter class:
此处引发异常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 尝试过,但没有任何效果。
那么问题是什么?。我没找到。
如
将代码更改为
BasicInterpreter basic = new BasicInterpreter(Opcodes.ASM5) { // <- the crucial point
@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;
}
};
解决这个问题。我也会更新另一个答案。