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

Mahmood Ali mahmood at MIT.EDU
Tue Mar 25 23:25:58 EDT 2008

Hi Telmo,

Thank you for noticing this.

On Mar 25, 2008, at 10:23 PM, Telmo wrote:

> 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.
Let me try to present your observation in a different way:

When you specify List<@ReadOnly Object> it notices that you are  
assigning @ReadOnly Object to E (in List<E>) where E extends Object.   
The BasetypeVisitor realizes that @ReadOnly Object is not a subtype of  
Object, thus issue an error.

> I have two possible ideas to fix this bug: [...]
I think that the fix need to be elsewhere, and I have been thinking  
about how to do this for a bit.  Currently the framework have a  
concept of the ultimate supertype, so it assumes that it is always the  
un-annotated java.lang.Object.  In the case of E, the javac and  
framework assumes that E needs to extend the ultimate root which is  
falsely Object.

I think that the best fix is that the AnnotatedTypeFactory stores the  
type of the ultimate root (which is @ReadOnly Object), so E (in  
List<E>) will have @ReadOnly as an upper bound.  I think that this  
gives you a solution for all the problems that we could potentially  
have.  I started working on this a bit ago, but finding the right  
places to actually call it isn't that trivial.

> 1. Check on BaseTypeVisitor if the upper bound is Object, and if so,  
> do not
> call commonAssignmentCheck
For the short term, I think we could implement this approach.  The  
proposed code however ignores whether the user explicitly restricted  
the upper bound of E (in NonNull test there was E extends @NonNull  
Object), and that's the reason the test was failing after the patch.

I made a variant of the proposed test where it tests whether there are  
any annotations on object in addition to checking whether the  
upperbound is an object or not (note TypesUtils.isObject() and  

However, this may require Javari to add the implicit Mutable  
annotation if the user explicitly specifies the upper bound, e.g. E  
extends Object, meaning that E extends @Mutable Object.

The new code should be checked in now.


P.S. typeVar.getUpperBound() should never be null, so I don't think  
that we need to have if (typeVar.getUpperBound() != null) { ... }
P.P.S. the lazy initializer for wildtype and typevariable should  
really depend on AnnotatedTypeFactory.

More information about the checkers mailing list