All,
Currently, any type-qualifier annotation can be written on an exception parameter, but there is no enforcement that a caught exception will be of that qualified type. For example:
try{
@A Throwable t = ...;
throw t; // no warning even if @B <: @A
} catch( @B Throwable e){
}
Related, type-qualifier annotation on types in a throws clause are not checked. For example,
void foo() throws @B Throwable {
@A Throwable t = ...;
throw t; // no warning even if @B <: @A
}
If an exception parameter or type in a throws clause is an unchecked exception, a type checker* cannot verify these qualified typed. So, qualifiers in these locations must be top.
If an exception parameter or type in a throws clause is a checked exception, a type checker could verify these qualifiers. This would be a bit complicated because each throws statement could match more than one exception parameter or type in a throws clause. (It would probably take a week or two to get the design and implementation correct.)
I propose, for now, we treat checked exceptions conservatively -- force qualifiers in these locations to be top. Then perhaps during the bug fix release next year, we add more precise checking for checked exceptions.
Thoughts?
-Suzanne
* In the case of the Nullness Checker, both exception parameters and types in throws clauses can be @NonNull because a null pointer exception is thrown if null would be thrown. In general, the Nullness Checker will need to override checking of exceptions parameters and types in throws clauses.