ASM BasicInterpreter IllegalStateException

Oct 21 2020

나는이 질문을 여기에서 보았고 받아 들여진 대답에서 코드를 컴파일하려고합니다. 불행히도 코드의이 부분에서 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으로 시도했지만 아무것도 작동하지 않습니다.

그래서 문제는 무엇입니까?. 나는 그것을 찾을 수 없었다.

답변

2 Holger Oct 21 2020 at 22:37

이 답변 에서 설명했듯이 하위 클래스는 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;
    }
};

이 문제를 해결합니다. 다른 답변도 업데이트하겠습니다.