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

Consider omitting type annotations from type error diagnostics

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 23
    • None
    • tools
    • None
    • b26

      Error messages like 'List<@Nullable String> cannot be assigned to ...' can be confusing, because the annotations (e.g. @Nullable) do not affect Java's type system. It might be clearer to omit the annotations when printing types in diagnostics.

      ===
      import static java.lang.annotation.ElementType.TYPE_USE;

      import java.lang.annotation.Target;
      import java.util.List;

      @Target(TYPE_USE)
      @interface A {}

      public class T {
        List<@A Number> f(List<String> xs) {
          return xs;
        }
      }
      ===

      Actual:

      $ javac -fullversion ~/T.java
      javac full version "19-ea+33-2224"
      T.java:11: error: incompatible types: List<String> cannot be converted to List<@A Number>
          return xs;
                 ^
      1 error

      Suggested:

      error: incompatible types: List<String> cannot be converted to List<Number>

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

              Created:
              Updated:
              Resolved: