Skip to content

Annotation's short parameter value is always 0 #548

@liangzengle

Description

@liangzengle

Annotation's parameter which type is short, it's value in AnnotationInfo is always 0.

@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
public @interface MyAnnotation {
    short value();
}
@MyAnnotation(1)
public class MyClass {
    public static void main(String[] args) {
        new ClassGraph()
                .enableAllInfo()
                .scan(ForkJoinPool.commonPool(), 8)
                .getClassesWithAnnotation(MyAnnotation.class.getName())
                .forEach(classInfo -> {
                    AnnotationInfo annotationInfo = classInfo.getAnnotationInfo(MyAnnotation.class.getName());
                    Object value = annotationInfo.getParameterValues().get("value").getValue();
                    System.out.println(value); // prints: 0
                });
    }
}

I beleive the short type value is handled incorrectly at return (short) cpReadUnsignedShort(reader.readUnsignedShort());
And I tried cpReadInt instead of cpReadUnsignedShort, it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions