[jdk17] RFR: 8270916: Update java.lang.annotation.Target for changes in JLS 9.6.4.1

Guoxiong Li gli at openjdk.java.net
Fri Aug 20 10:34:28 UTC 2021


On Thu, 22 Jul 2021 19:38:07 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> Given changes in JLS 9.6.4.1, JDK-8261610 in Java SE 17, the statements about annotation applicability made in java.lang.annotation.Target need to be updated to match.
>> 
>> Please also review the corresponding CSR: https://bugs.openjdk.java.net/browse/JDK-8270917
>
> CSR now approved.

Hi @jddarcy,

Sorry for the delay.

I notice the current javac code(shown below) doesn't meet the JLS 9.6.4.1 .
The code doesn't mark `TYPE_PARAMETER` as the default target.
Because the PR https://github.com/openjdk/jdk/pull/622 and https://github.com/openjdk/jdk/pull/2412 , which tried to fix this problem, is earlier than the [JDK-8261610](https://bugs.openjdk.java.net/browse/JDK-8261610), [JDK-8270916](https://bugs.openjdk.java.net/browse/JDK-8270916), and [JDK-8270917](https://bugs.openjdk.java.net/browse/JDK-8270917).

According to the new JLS 9.6.4.1, the javac compiler should be adjusted to add `TYPE_PARAMETER` as the default target.
Should we fix the compiler issue in JDK17? But it seems too late to do that.
Maybe JDK18 is a good place. What do you think about it? Any ideas are appreciated.


// com.sun.tools.javac.comp.Check.java
    private Name[] dfltTargetMeta;
    private Name[] defaultTargetMetaInfo() {
        if (dfltTargetMeta == null) {
            ArrayList<Name> defaultTargets = new ArrayList<>();
            defaultTargets.add(names.PACKAGE);
            defaultTargets.add(names.TYPE);
            defaultTargets.add(names.FIELD);
            defaultTargets.add(names.METHOD);
            defaultTargets.add(names.CONSTRUCTOR);
            defaultTargets.add(names.ANNOTATION_TYPE);
            defaultTargets.add(names.LOCAL_VARIABLE);
            defaultTargets.add(names.PARAMETER);
            if (allowRecords) {
              defaultTargets.add(names.RECORD_COMPONENT);
            }
            if (allowModules) {
              defaultTargets.add(names.MODULE);
            }
            dfltTargetMeta = defaultTargets.toArray(new Name[0]);
        }
        return dfltTargetMeta;
    }


Best Regards,
-- Guoxiong

-------------

PR: https://git.openjdk.java.net/jdk17/pull/256


More information about the core-libs-dev mailing list