Expected behavior for annotation property with duplicate value definition

Rafael Winterhalter rafael.wth at gmail.com
Wed May 5 08:53:24 UTC 2021


Hello,

I was wondering if the current OpenJDK behavior should yield an exception
or if it is accidental and if so, if it should be altered to avoid
surprising behavior. If an annotation:

@interface Sample {
  String v();
}

is added to a member where the property 'v' is assigned a value twice, the
last added value is returned by the reflection API and no error is raised.
I recently observed this for ASM-generated code where a value was added
twice and it led to a longer bug search, but technically this could of
course also happen when javac or other language compilers generate code. I
wonder therefore if this should rather yield an error or if this behavior
should be documented somewhere in case that the change would be possibly
too disruptive for existing code.

I am happy to provide a patch to OpenJDK but wonder what exception should
be thrown when reading the property.

Best regards, Rafael


More information about the core-libs-dev mailing list