Skip to content

getAnnotations() returns empty list for removed members due to eager initialization #497

Closed

Description

@bclozel

When a method is marked as "removed", calling getAnnotations() on the corresponding JApiMethod often returns an empty list, even if the member had annotations in the old version.

I think the bug is caused by eager initialization of annotations during the constructor phase of the model classes. japicmp calls computeAnnotationChanges() directly inside the constructors of these classes. This method asks javassist for the AnnotationsAttribute.visibleTag attribute. If I'm not mistaken, javassist parses class file attributes lazily. At the exact moment japicmp instantiates the model object, javassist has not fully parsed the attributes for that removed member yet, so getAttribute() returns null.

I have somewhat validated this analysis in my build. I am manually calling javassist in a rule, once that javassist has fully loaded the attributes, but japicmp has already cached the empty list. This local patch works. Could getAnnotations() lazily collect the information from javassist?

I think the same issue exists for fields, classes and methods.

Steps to Reproduce:

  1. Create a class with a constructor annotated with @Deprecated
  2. In a newer version, remove the constructor.
  3. Run japicmp and inspect the JApiConstructor for the removed constructor.
  4. jApiConstructor.getAnnotations() will be empty, despite the old constructor having the @Deprecated annotation.

Activity

  1. siom79 commented on Apr 9, 2026

    @siom79
    Owner

    Thanks a lot for reporting and even analyzing the root cause. The PR #498 fixes the issue.

  2. bclozel commented on Apr 10, 2026

    @bclozel
    Author

    That was fast, thanks a lot for your work on this project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions