1

次のコードを実行します。

    CfField f = ...
    CtClass classeEnglobante = f.getDeclaringClass();
    ClassPool pool = classeEnglobante.getClassPool();
    ConstPool constPool = classeEnglobante.getClassFile().getConstPool();

    AnnotationsAttribute attr = new AnnotationsAttribute(constPool , AnnotationsAttribute.visibleTag);
    Annotation a = new Annotation(constPool, pool.get("org.hibernate.annotations.Index"));
    a.addMemberValue("name", new StringMemberValue("idx_" + p.getNomMinuscule(), constPool));
    attr.addAnnotation(a); // Here is the line 245

そして、このNPEが発生します:

java.lang.NullPointerException
    javassist.bytecode.annotation.ArrayMemberValue.write(ArrayMemberValue.java:132)で
    javassist.bytecode.annotation.Annotation.write(Annotation.java:317)で
    javassist.bytecode.AnnotationsAttribute.setAnnotations(AnnotationsAttribute.java:246)で
    com.mycompany.MyClass(MyClass.java:245)で
4

1 に答える 1

1

この質問は私の問題を解決します。何らかの理由で、javassist3.1.2.GAにバグがあります。だからここに私のエラーとそれに対する解決策があります:

間違った:バグが発生しやすい

Annotation a = new Annotation(constPool, pool.get("org.hibernate.annotations.Index"));

正解:バグなし

Annotation a = new Annotation("org.hibernate.annotations.Index", constPool);
于 2011-08-09T17:01:52.550 に答える