[Checkers] <@ReadOnly Object> generic type (fwd)

Matt Papi mpapi at csail.mit.edu
Tue Mar 25 23:23:24 EDT 2008


Telmo,

> The compiler API sees the type
> 
> List<@ReadOnly Object>
> 
> as
> 
> List<@ReadOnly Object extends Object>
> 
> , causing the framework to emit an error, since @ReadOnly Object is not a 
> subtype of Object.

This is actually the intended behavior. It's because List is declared as 
"List<T>", which is really "List<T extends Object>", which is (in the 
current implementation) really "List<T extends @Mutable Object>".

I should have realized that this would be an issue for 
@ReadOnly/@Mutable, though it didn't break any tests when I committed it 
last week (and still doesn't seem to, despite 
tests/javari/ForEnhanced.java using "List<@ReadOnly Object>").

> I have two possible ideas to fix this bug:
> 
> 1. Check on BaseTypeVisitor if the upper bound is Object, and if so, do not 
> call commonAssignmentCheck

This one will certainly break the NonNull checker. See the GenericArgs 
test case: if there's a class Cell<T extends @NonNull Object> and it's 
instantiated via "new Cell<@Nullable Object>()", that should (and 
currently does) cause an error.

> 2. Modify the local (javari) version of commonAssignmentCheck, to add the 
> @ReadOnly annotation to the upperbound if it is object and if the error key is 
> "generic.argument.invalid".

The code to do this probably doesn't belong in commonAssignmentCheck, so 
I don't think this is ideal (as you mentioned). Two fixes that I think 
are a bit cleaner are:

- in the Javari-annotated JDK, change List<T> to List<T extends 
@ReadOnly Object>, etc. (probably much more work than is worthwhile!)

- in the framework, make it possible for a checker to override the 
default upper bound (so Javari can specify the default to be @ReadOnly 
Object), or somehow determine what it should be using the checker's 
annotation relation graph (eventually)

> The nonnull tests do not all pass either before or after the fix

Are you sure they don't pass before the fix? This might be part of the 
confusion -- as of r2018, and at least since r2008, the test suites of 
all the checkers (including NonNull and its GenericArgs test) are 
completely passing.

- Matt



More information about the checkers mailing list