Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8334055

Unhelpful 'required: reference' diagnostics after JDK-8043226

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 24
    • 23
    • tools
    • b07

    Description

      JDK-8043226 improved 'scoping construct cannot be annotated' diagnostics to more clearly describe the error.

      Given:

      import java.util.*;
      import java.lang.annotation.*;

      @Target(ElementType.TYPE_USE) @interface TA {}

      class T {
        @TA Map.Entry<?, ?> x;
        List<@TA NoSuch> y;
        List<@TA java.lang.Object> z;
      }

      The error on 'x' was updated from:

      T.java:7: error: scoping construct cannot be annotated with type-use annotation: @TA
        @TA Map.Entry<?, ?> x;
                     ^

      to:

      T.java:7: error: type annotation @TA is not expected here
        @TA Map.Entry<?, ?> x;
                     ^
        (to annotate a qualified type, write Map.@TA Entry<?,?>)

      Additionally, that change tried to improve diagnostics for type annotations package names, changing the diagnostic on 'z' from:

      T.java:9: error: cannot find symbol
        List<@TA java.lang.Object> z;
                 ^
        symbol: class java
        location: class T

      to:

      T.java:9: error: type annotation @TA is not expected here
        List<@TA java.lang.Object> z;
                 ^
        (to annotate a qualified type, write java.lang.@TA Object)

      To support the second case, attribution of annotated types was updated to handle package names: https://github.com/openjdk/jdk/blob/612b6896d28cebf61ef024709ff3afb5e3ee0dde/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java#L5246-L5251

      The change to support package names had unintended side effects for missing symbols, e.g. before:

      T.java:8: error: cannot find symbol
        List<@TA NoSuch> y;
                 ^
        symbol: class NoSuch
        location: class T

      after:

      T.java:8: error: unexpected type
        List<@TA NoSuch> y;
             ^
        required: reference
        found: NoSuch

      The 'required: reference' / 'found: NoSuch' details are confusing. They're happening because NoSuch is being resolved as a package that doesn't exist, and then the error for an unexpected package type is reported before type annotation validation happens.

      I'd like to back out the change to the handling of package names for now.

      Attachments

        Issue Links

          Activity

            People

              cushon Liam Miller-Cushon
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: