[Records] Component annotations not propagated when explicit canonical constructor is given
Gunnar Morling
gunnar at hibernate.org
Sun Jan 19 21:14:48 UTC 2020
Hi,
I'm observing the following behaviour around annotations on record
components, using JDK 14 b32. I'm putting an annotation to a record
component:
public record Person(@NotNull String name) {}
In this case the @NotNull annotation is propagated to the
corresponding parameter of the generated constructor, from where I can
obtain it using reflection. This is not the case though when I
explicitly declare the canonical constructor:
public record Person(@NotNull String name) {
public Person {
// ...
}
}
In this case the annotation isn't propagated, and it won't be
retrievable from that constructor's parameter via reflection.
Is this behaviour intended or is it a bug actually? I lean towards the
latter, as I don't explicitly define the parameter in the constructor,
so I'd expect the annotations given on the component to still be
propagated.
If it *is* intended, it'd make my use case a bit more complex, as I'd
want to be able to put other annotations to the canonical constructor
*itself*, while still getting all the component annotations propagated
to its parameters.
Thanks a lot,
--Gunnar
More information about the amber-dev
mailing list