[JSR308] Receiver on field initializers

Artemus Harper subanark at gmail.com
Fri May 9 15:21:54 EDT 2008


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

The problem is that although a constructor can have its receiver annotated,
it will implicitly initialize fields (for those that have an initializer).
The initializer for those fields may refer to this.

E.g.
public class Test {
   public String s = test();
   public Test() @SomeAnnotation {
   }
   public String test()
   {
      //Uses 'this'
      return "Test";
   }
}

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
    }
}
Stack Trace:
java.lang.IllegalArgumentException: null tree
        at
checkers.types.AnnotatedTypeFactory.getAnnotatedType(AnnotatedTypeFactory.java:540)
        at
checkers.types.AnnotatedTypeFactory.getCurrentMethodReceiver(AnnotatedTypeFactory.java:669)
        at
checkers.types.AnnotatedTypeFactory.getSelfType(AnnotatedTypeFactory.java:681)
        at
checkers.types.AnnotatedTypeFactory.getReceiver(AnnotatedTypeFactory.java:722)

getSelfType seems to assume that the expression is in a method.
-- 
Artemus Harper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.csail.mit.edu/pipermail/jsr308/attachments/20080509/6a08fe4a/attachment.htm 


More information about the JSR308 mailing list