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, 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 using the compiler API, changes from
WARNING
toMANDATORY_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 to the warning logging infrastructure have made this task easier to implement.
- csr of
-
JDK-8361401 Warnings for use of Sun APIs should not be mandatory
-
- Open
-