JDK-8361402 : Warnings for use of Sun APIs should not be mandatory
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Draft
  • Resolution: Unresolved
  • Submitted: 2025-07-04
  • Updated: 2025-07-04
Related Reports
CSR :  
Description
Summary
-------

During Java 8 development, the warnings for use of Sun API elements (e.g. `com.sun.misc.Unsafe`) were accidentally promoted to the status of *mandatory warnings*.

Problem
-------

Java 8 brought many changes to the Java compiler. One such change is deferred attribution -- the ability to type check an expression and later ignore the result of such attribution. Deferred attribution was a key to implement support for lambda expressions and method references.

Due to the way deferred attribution works, it is crucial that all javac diagnostics are reported in an uniform fashion, typically by calling `Log::report`. One class of warnings, namely warnings for use of Sun API element, was reported through a different method -- namely `Log::strictWarning`. This method did *not* call `Log::report`, and caused issues with deferred attribution.

To address the [issue](https://bugs.openjdk.org/browse/JDK-7148622), at the time it was decided to use `Log::mandatoryWarning` to report such warnings instead. However, this change had some adverse effects:

 * the warning could now be omitted in case the compiler generates more than 100 warnings
 * more importantly, the warning kind, which can be [seen](https://download.java.net/java/early_access/jdk25/docs/api/java.compiler/javax/tools/Diagnostic.Kind.html) using the compiler API, changes from `WARNING` to `MANDATORY_WARNING`. This is undesirable, as such warnings, while important, are not mandated by the JLS.

Solution
--------

The solution is to change the compiler to emit a non-mandatory warning, but one that cannot be suppressed or disabled -- similar to what happened prior to Java 8. Recent [changes](https://bugs.openjdk.org/browse/JDK-8350514) to the warning logging infrastructure have made this task easier to implement.