[Checkers] Nullness checker
Michael Ernst
mernst at cs.washington.edu
Sat Mar 21 23:53:19 EDT 2009
Adam-
Thanks for your message; it's always great to hear from you, and your
comments help improve the Checker Framework as well as the nullness
checker.
I'm copying your mail to checkers at lists.csail.mit.edu. That contains more
people than me, so you are likely to get a faster and more authoritative
answer.
-Mike
> Hello,
>
> thinking about it a bit more, I guess I can answer myself that the
> AnnotationValueVisitor should declare the type as @Nullable.
>
> I was looking at the skeleton classes and how you handle generics, and
> there you have for example:
>
> public interface Map<K extends @NonNull Object, V extends @NonNull
> Object>
>
> Doesn't that prohibit type parameters that allow null values at all?
> After all, @Nullable Object doesn't extend @NonNull Object, it's the
> other way round. And why do you write this at all, if the default
> qualifier is @NonNull? Doesn't this apply also to type parameters? I
> could be of course missing some obvious variance argument on why this
> is correct ;)
>
> (another by the way: Map.get should accept a @Nullable parameter)
>
> Adam
>
> On Mar 21, 2009, at 12:37 PM, Adam Warski wrote:
>
> > Hello,
> >
> > I'm continuing this weekend to try to make the nullness checker pass
> > on my typestate checker :) And I've got a question ...
> >
> > I've got an AnnotationValue visitor there, which can return null
> > values, so I declared it as:
> >
> > public class AnnotationAsAnnotationValueVisitor implements
> > AnnotationValueVisitor</*@Nullable*/ AnnotationMirror, Void> {
> > public /*@Nullable*/ AnnotationMirror visit(AnnotationValue av,
> > Void aVoid) { return null; }
> > // etc
> > }
> >
> > (by the way - maybe it would make sense to make any object of "Void"
> > class nullable by default? It would be pretty hard to assign a
> > nonnull value to it :) )
> >
> > However I get the following warning from the checker:
> >
> > [java] /Users/adamw/jsr308/jsr308-typestate-checker/src/checkers/
> > typestate/AnnotationAsAnnotationValueVisitor.java:16: invalid type
> > argument;
> > [java] public class AnnotationAsAnnotationValueVisitor
> > implements AnnotationValueVisitor</*@Nullable*/ AnnotationMirror,
> > Void> {
> >
> > [java
> > ] ^
> > [java] found : @Nullable AnnotationMirror
> > [java] required: @NonNull Object
> >
> > (the arrow points to A in /*@Nullable*/ AnnotationMirror :) )
> >
> > As I understand type annotations on type parameters, the semantics
> > is that this behaves a bit like wildcards, meaning that the type
> > passed must be annotated with the type annotation or a sub-type
> > annotation. Is that correct?
> >
> > I don't have any idea however why I get the error. Maybe it is
> > required that the AnnotationValueVisitor declares the type
> > parameters as Nullable? And the solution is to add it annotated as
> > such to the jdk/nullness/src?
> >
> > --
> > Thanks,
> > Adam
>
More information about the checkers
mailing list