Wrong typepath for array type annotations
My test class contains an string array field with type annotations:
File TestTypeAnnotationOnFieldArra.java
@NotNull
String @NotEmpty [] strArr = null;
The type annotations are self written:
File NotNull.java
package de.heinerkuecker.and so on;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention( RetentionPolicy.RUNTIME )
@Target( { ElementType.TYPE_USE } )
@Inherited
@Documented
public @interface NotNull
{
}
File NotEmpty.java
package de.heinerkuecker.and so on;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention( RetentionPolicy.RUNTIME )
@Target( { ElementType.TYPE_USE } )
@Inherited
@Documented
public @interface NotEmpty
{
}
I parse the byte code of TestTypeAnnotationOnFieldArra.class with an
implementation class of
org.objectweb.asm.FieldVisitor
public final class AsmDomFieldVisitor
extends FieldVisitor
{
@Override
public AnnotationVisitor visitTypeAnnotation(
final int typeRef ,
final TypePath typePath ,
final String desc ,
final boolean visibleAtRuntime )
{
System.out.println( ( new Exception() ).getStackTrace()[ 0 ] + " typeRef: " +
typeRef + " typePath: " + typePath + " desc: " + desc + " visibleAtRuntime: " +
visibleAtRuntime );
In my console following output occurs:
de.heinerkuecker.and so
on.AsmDomFieldVisitor.visitTypeAnnotation(AsmDomFieldVisitor.java:87) typeRef:
318767104 typePath: null desc: Lde/heinerkuecker/and so
on/test_data/annotation_def/NotEmpty; visibleAtRuntime: true
de.heinerkuecker.and so
on.AsmDomFieldVisitor.visitTypeAnnotation(AsmDomFieldVisitor.java:87) typeRef:
318767104 typePath: [ desc: Lde/heinerkuecker/and so
on/test_data/annotation_def/NotNull; visibleAtRuntime: true
The typepath of the NotEmpty annotaion is null, which the entire type means and
the typepath of the NotNull is '[', which the array element type means.
This assignment of annotation to typepath is vice versa to my expectation.
Thank you for help and for the amazing asm lib.
Heiner