Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation's short parameter value is always 0 #548

Closed
liangzengle opened this issue Aug 14, 2021 · 3 comments
Closed

Annotation's short parameter value is always 0 #548

liangzengle opened this issue Aug 14, 2021 · 3 comments

Comments

@liangzengle
Copy link

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.

@lukehutch
Copy link
Member

@liangzengle Wow, great job debugging the problem right down to the source! You're totally right, all types other than long use a full 4 bytes (in big endian order) in the constant pool table. So the top two bytes will be zero for a short.

Fixed and released in version 4.8.114. Xiexie!

@lukehutch
Copy link
Member

PS @liangzengle make sure you call .scan() in try-with-resources, so that the returned ScanResult is closed when you have finished with it.

@liangzengle
Copy link
Author

@lukehutch Thanks for the heads up and the fast fix-release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants