Handling for new warning?

Mike Duigou openjdk at duigou.org
Tue Sep 24 22:56:37 UTC 2019


The proposed change is to add a lint level warning, ie. 
-XLint:runtime-undeclared , suggestion to add the unrequired but missing 
throws declarations for RuntimeException et al. The advantage to 
providing the complete throws including RuntimeExceptions is to make 
them more visible and encourage handling of them. We have one good 
example of a library which does declare the RuntimeException that are 
thrown, the JDK. Having those optional declarations has already been 
deemed invaluable and necessary to writing good tests, the most direct 
example being the JCK. The intent is to encourage declaration of 
RuntimeExceptions that might be thrown so that callers can better plan 
for the potential behaviour of methods both in their production code and 
in tests.

The check will apply to all instances of RuntimeException and all 
subclasses.

This change is one of the two proposals I made for improving exceptions 
in my CodeOne talk "Exceptions 2020", the other change requires JLS 
changes so I decided to pursue this one first.

Cheers,

Mike


On 2019-09-24 12:31, mark.reinhold at oracle.com wrote:
> 2019/9/24 10:31:00 -0700, openjdk at duigou.org:
>> I am working on a feature for javac that adds a new lint level warning
>> for undeclared thrown RuntimeExceptions.
> 
> RuntimeExceptions are unchecked exceptions.  Do you mean to require 
> that
> they be mentioned in `throws` clauses, even though the language doesn’t
> require that?  If so, why is that a good idea?
> 
> Will this check apply only to direct instances of `RuntimeException`, 
> or
> to instances of that class and all its subclasses?
> 
> - Mark


More information about the compiler-dev mailing list