Record component annotations with target=PARAMETER

Vicente Romero vicente.romero at oracle.com
Tue Dec 17 14:29:56 UTC 2019


Hi Tagir,

Yes the spec should be updated, you are correct that `parameter` should 
be added here,

Thanks,
Vicente

On 12/17/19 5:10 AM, Tagir Valeev wrote:
> Hello!
>
> Current records JLS spec draft [1] says:
>
> a record component but T is not applicable to record component
> declarations, field declarations, method declarations, or type
> contexts.
>
> However, javac doesn't fail if the annotation target is parameter:
>
> import java.lang.annotation.*;
>
> record Foo(@Anno int x) {}
> @Target(ElementType.PARAMETER)
> @interface Anno {}
>
> This code compiles and the canonical constructor is annotated with
> Anno. To me, the javac behavior is expected and spec should be updated
> to include "parameters":
>
> a record component but T is not applicable to record component
> declarations, field declarations, method declarations, parameters, or
> type contexts.
>
> What do you think? I'm implementing error highlighting for records in
> IntelliJ now. Should I follow the spec or javac behavior?
>
> With best regards,
> Tagir Valeev.
>
> http://cr.openjdk.java.net/~gbierman/jep359/jep359-20191125/specs/records-jls.html#jls-9.7.4



More information about the amber-spec-experts mailing list