ASM BasicInterpreter IllegalStateException
Vi esta pregunta aquí en SO y estoy tratando de compilar el código de la respuesta aceptada. Desafortunadamente, sigo recibiendo una IllegalStateException en esta parte del código:
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;
}
};
Con el seguimiento de la pila:
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)
La excepción se genera aquí en la clase BasicInterpreter :
public BasicInterpreter() {
super(/* latest api = */ ASM8);
if (getClass() != BasicInterpreter.class) {
throw new IllegalStateException(); // at this line
}
}
Intenté heredar el BasicInterpreter pero sigo recibiendo la misma excepción.
class BasicInterpreterLocal extends BasicInterpreter{} // Throws an IllegalStateException
Lo intenté con asm 7. *, 8. **, 9.0, pero nada funciona.
¿Entonces, cuál es el problema?. No pude encontrarlo.
Respuestas
Como se explica en esta respuesta , las subclases deben usar el constructor que acepta un número de versión de la biblioteca para determinar el nivel de compatibilidad de la biblioteca ASM. Parece que la versión 5 de la biblioteca ASM, que el código estaba usando inicialmente, no verificó este requisito. Pero está utilizando una versión más reciente (8, aparentemente) de la biblioteca que hace cumplir esta regla.
Cambie el código a
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;
}
};
para arreglar esto. También actualizaré la otra respuesta.