-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array creation annotation checks #928
base: master
Are you sure you want to change the base?
Changes from 2 commits
13ba984
04f7dc3
beff18b
6f8ee2a
398ca37
95b896d
a8351aa
e7db307
eb46944
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -348,7 +348,11 @@ public Void visitNewArray(NewArrayTree tree, Void p) { | |||||||||
componentType.getAnnotations(), | ||||||||||
type.toString()); | ||||||||||
} | ||||||||||
|
||||||||||
List<? extends AnnotationMirror> annotations = | ||||||||||
TreeUtils.annotationsFromArrayCreation(tree, 0); | ||||||||||
if (AnnotationUtils.containsSame(annotations, NULLABLE)) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks for bringing up |
||||||||||
checker.reportWarning(tree, "new.array.nullable.ignored"); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Related to the discussion of the error key, the other |
||||||||||
} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use this error message? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because it is not about the component type. |
||||||||||
return super.visitNewArray(tree, p); | ||||||||||
} | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ nulltest.redundant=redundant test against null; "%s" is non-null | |||||||||||||
instanceof.nullable=instanceof is only true for a non-null expression | ||||||||||||||
instanceof.nonnull.redundant=redundant @NonNull annotation on instanceof | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a similar warning for object and array creations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to move checker-framework/checker/tests/nullness-warnredundantannotations/RedundantAnnotation.java Lines 33 to 38 in 33399f9
|
||||||||||||||
new.array.type.invalid=annotations %s may not be applied as component type for array "%s" | ||||||||||||||
new.array.nullable.ignored=nullable annotation on array element type ignored, must be nonnull | ||||||||||||||
new.class.type.invalid=the annotations %s do not need be applied in object creations | ||||||||||||||
nullness.on.constructor=do not write nullness annotations on a constructor, whose result is always non-null | ||||||||||||||
nullness.on.enum=do not write nullness annotations on an enum constant, which is always non-null | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment why this doesn't use
type
? That is already the type of the array creation. Was it because@PolyNull
would already be substituted?