Record component annotations with target=PARAMETER

Tagir Valeev amaembo at gmail.com
Tue Dec 17 10:10:30 UTC 2019


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