JDK-8291643 : Consider omitting type annotations from type error diagnostics
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-08-01
  • Updated: 2024-06-22
  • Resolved: 2024-06-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 23
23 b26Fixed
Related Reports
Relates :  
Relates :  
Description
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>
Comments
Changeset: 7564949a Author: Liam Miller-Cushon <cushon@openjdk.org> Date: 2024-06-05 19:10:13 +0000 URL: https://git.openjdk.org/jdk/commit/7564949a56b533b9d955ff5feee75afd18e51f74
05-06-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16578 Date: 2023-11-09 00:47:10 +0000
09-11-2023

A couple more notes: * type annotations are already dropped during some operations on types (e.g. substitution) and so don't consistently show up in type related diagnostics * this is somewhat related to https://bugs.openjdk.org/browse/JDK-8042981 (remove type-use annotations from Types' utility methods)
01-08-2022