[Checkers] Modification to AnnotatedTypeVariable and AnnotatedWildcardType

Mahmood Ali mahmood at MIT.EDU
Tue Jun 3 18:46:20 EDT 2008


Hi everyone,

I am considering overriding getAnnotations() in AnnotatedTypeVariable  
and AnnotatedWildcardType.  What follows is an explanation of the  
problem and the propose change.

Problem (Surprise):
For an annotation FOO, type.hasAnnotation(FOO) and the notion of the  
type being FOO-qualified is different.

Currently, it is not sufficient to check for the presence of an  
annotation via .hasAnnotation().  In the case of type variables or  
wildcard, one needs to check the presence of the annotation in extends/ 
super bound.

Workaround:
Throughout the nonnull checker and interned checker there is code like:
 > if (!TreeUtils.isSelfAccess(node) && !checker.isSubtype(NN_OBJECT,  
type))
 >     checker.report(Result.failure("dereference.of.nullable",
 >             node.getExpression().toString()), node);

Notice the test for a type being a subtype of a nonnull Object.

Desired Code:
 > if (!TreeUtils.isSelfAccess(node) && !type.hasAnnotation(NONNULL))
 >     checker.report(Result.failure("dereference.of.nullable",
 >             node.getExpression().toString()), node);

In my opinion, this is clearer and causes less surprise.  Furthermore,  
it's more efficient as we don't climb up the supertype hierarchy to  
Object for every type.

Proposed solution:
Override getAnnotations() in AnnotatedWildcardType and  
AnnotatedTypeVariable, so that it would return the annotations of the  
super/extends bound if no annotations are present on the type itself.

This makes the test for the presence of an annotation more trivial.

Any ideas?  Objections?

- Mahmood
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/mailman/private/checkers/attachments/20080603/521f09dc/attachment.htm 


More information about the checkers mailing list