[JSR308] Receiver on field initializers

Mahmood Ali mahmood at MIT.EDU
Sat May 10 19:35:47 EDT 2008


Greetings,

Thank you very much for your email and observation!

> What exactly is the annotations on the receiver of a field  
> initializer?

Currently, the receiver is the annotated type of the enclosing class.   
We realize that this may be problematic for some checkers.

It has been proposed that we should have the least restricted type  
(actually least upper bound) of all the constructors, including the  
synthetic constructors.  We have not gotten to it yet, but hopefully  
it will make it into the following stable release.

> Also, when I tried to ask the API for the receiver I got an  
> exception (In my
> case I'm doing escape analysis):
>
> public class EscapeVisitor extends BaseTypeVisitor<Void, Void> {
>     @Override
>     public Void visitVariable(VariableTree node, Void p) {
>         AnnotatedTypeMirror type =
> factory.getReceiver(node.getInitializer()); //throws exception
>     }

Thanks for this bug report.  The bug can be fixed simply by returning  
null if enclosingMethod is null in  
AnnotatedTypeFactory.getCurrentMethodReceiver().

However, this particular bug should not occur if your visitor is  
extending BaseTypeVisitor<Void Void>.  Can you please send us (me) a  
copy of your checker to be able to replicate your findings?

Regards,
Mahmood



More information about the JSR308 mailing list