Problem
The passAnnotations style feature allows specifying a "parent" annotation, or an annotation of annotations, which should result in all other annotations annotated with that "parent" annotation to also be passed along on attributes to the generated immutable implementation.
However, if an attribute has multiple annotations that share the same "parent" annotation that's present in passAnnotations, only one of them will actually be passed along to the generated immutable implementation.
Example
With the following annotations defined:
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ParentAnnotation {}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@ParentAnnotation
public @interface ChildAnnotationA {}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@ParentAnnotation
public @interface ChildAnnotationB {}
and the following immutable model:
@Value.Immutable
@Value.Style(passAnnotations = {ParentAnnotation.class})
public interface ExampleModel {
@ChildAnnotationA
@ChildAnnotationB
String attributeWithBothChildAnnotations();
}
only one of the child annotations (either @ChildAnnotationA or @ChildAnnotationB) will be present on the attributeWithBothChildAnnotations() method in the generated immutable implementation.
A more complete example showing this is available at: https://github.com/jhartz/ImmutablesPassAnnotationsBug
including unit tests that show that this issue only occurs when multiple annotations share the same "parent" annotation that's present in the style's passAnnotations (and not in other situations where there are multiple annotations on an attribute).
Problem
The
passAnnotationsstyle feature allows specifying a "parent" annotation, or an annotation of annotations, which should result in all other annotations annotated with that "parent" annotation to also be passed along on attributes to the generated immutable implementation.However, if an attribute has multiple annotations that share the same "parent" annotation that's present in
passAnnotations, only one of them will actually be passed along to the generated immutable implementation.Example
With the following annotations defined:
and the following immutable model:
only one of the child annotations (either
@ChildAnnotationAor@ChildAnnotationB) will be present on theattributeWithBothChildAnnotations()method in the generated immutable implementation.A more complete example showing this is available at: https://github.com/jhartz/ImmutablesPassAnnotationsBug
including unit tests that show that this issue only occurs when multiple annotations share the same "parent" annotation that's present in the style's
passAnnotations(and not in other situations where there are multiple annotations on an attribute).