JDK-8198611 : javax.lang.model APIs throws CompletionFailure or a subtype of CompletionFailure.
  • Type: CSR
  • Component: core-libs
  • Sub-Component: javax.lang.model
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 11
  • Submitted: 2018-02-23
  • Updated: 2018-03-07
  • Resolved: 2018-03-07
Related Reports
CSR :  
Description
Summary
-------

javax.lang.model API methods should no longer throw a javac-internal CompletionFailure exception.

Problem
-------

When javac internally reports missing classes using a CompletionFailure exception. This is an internal javac exception, that is not part of the APIs. Sadly, this exception may sometimes be thrown out from an API method to an API client. E.g. when an API client gets a TypeMirror by calling TypeElement.getSuperclass() for some TypeElement whose superclass is missing, this may lead to several different behaviors depending on the exact circumstances:

1. a DECLARED type, that will throw a CompletionFailure (once) at some 
point if used (e.g. when converted to Element and then invoking getKind() on that Element)
2. a DECLARED type that will not throw a CompletionFailure (because it 
was already thrown either inside javac code or in an API client that have caught the exception)
3. an ERROR type (if the reference to the missing class appeared in the source file)

Handling all these cases appears to be troublesome to the API clients. Moreover, as javac's error reporting depends on these exceptions, if the API client catches the exception, javac may miss an error report, which can lead to various breakages, e.g. javac crashes.

Solution
--------

The CompletionFailure is not thrown out of the API methods when API client is invoking them. TypeMirrors for representing missing classes should behave as ErrorTypes.

Specification
-------------

No API specification change. The behavior changes to be close to variant "3" from the list of possibilities in the Problem section. Variants "1" and "2" shall not happen. javac reports errors properly even in presence of API clients.

Comments
Moving to approved on the condition that a release note is written for this change.
07-03-2018

Thanks Jon, I updated the description to be more explicit that CompletionFailure is an internal exception.
27-02-2018

(Wow, comments allow wiki and HTML syntax!. The former comment just included a cut-n-paste of the standard comment block.)
23-02-2018

It is worth noting (maybe just here in a comment) that CompletionFailure is a javac-internal API, with the standard disclaimer at the head of the file: * <p><b>This is NOT part of any supported API. * If you write code that depends on this, you do so at your own risk. * This code and its internal interfaces are subject to change or * deletion without notice.</b> As such, it is a bug that it was allowed to escape into client code, and a regrettable albeit unsupported necessity that some code chose to catch and handle it.
23-02-2018