Annotations are lost in the case of duplicate methods #868
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This, I believe, is the root cause of a number of the "inconsistent behavior" bugs in the Scala module. For background, a normal Scala class:
will have a single accessor method visible to the JVM,
bar()
.ScalaAnnotationIntrospector
will report an implicit name of "bar" for this method, which enables its use as a a getter.Scala provides an annotation for end users to provide compatibility for libraries that are not Scala aware:
This class will have two accessors,
bar()
andgetBar()
. The first will be reported and enabled as above, and the second will be detected by Jackson's normal property detection. They'll be merged into the same property, and the duplicate resolution code inPOJOPropertyBuilder#getGetter
will resolve the duplication and discard the extras.The error is in merging annotations between the duplicates, and in merging annotations from creators into the
AnnotatedMethod
instances that represent them. The problem with the current code is that it only merges annotations from and into the last detected getter (the head of the linked list). Since reflection method order is non-deterministic in JVM 7+, which of the duplicates gets the annotations merged in is essentially random, though various platforms demonstrate tendencies in one direction or the other.In the "happy" case,
getBar
is detected last; since it's at the front of the linked list, it will get receive the annotations from the creator.getBar
is considered "better" bygetGetter
and is retained, so the annotation is visible to code looking for it.In the "unhappy" case,
bar
is detected last; it will receive the annotations from the creator, butgetBar
will not.getBar
will be chosen bygetGetter
, and so the creator annotations will be lost, and code looking for it will fail to do so.The fix covers this use case, and also covers the additional use case that annotations on
bar
andgetBar
were not mutually visible.The tests use 'isBar' to simulate the implicit naming that occurs in the Scala module. The linked list class also needed to be made
protected
to be visible to the tests.