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

Warnings for use of Sun APIs should not be mandatory

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • tools
    • None
    • behavioral
    • low
    • While it's possible for clients of the compiler API to see a change in the diagnostic kind, only one warning is affected by this change. As such, this change is unlikely to cause disruption.
    • Java API

      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 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 to the warning logging infrastructure have made this task easier to implement.

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated: