Hi Rafael,

On 5/05/2021 6:53 pm, Rafael Winterhalter wrote:
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 think you are describing generated bytecode that violates Java language rules for Annotation types. That is perfectly legal. The VM's notion of what an Annotation type is and how it must behave is much broader than that of the Java language.

Cheers,
David

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

Best regards, Rafael

Reply via email to