-
Notifications
You must be signed in to change notification settings - Fork 299
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
Don't report @Nullable type argument errors for unmarked classes #958
Changes from 4 commits
403f8f3
bec4bff
8ef8df9
765e1ec
a9bf295
e623404
14cf177
2b6ad6d
fce9c3f
055b250
06c01c1
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 |
---|---|---|
|
@@ -738,9 +738,13 @@ public Description matchParameterizedType(ParameterizedTypeTree tree, VisitorSta | |
if (!withinAnnotatedCode(state)) { | ||
return Description.NO_MATCH; | ||
} | ||
|
||
Symbol calledClass = castToNonNull(ASTHelpers.getSymbol(tree)); | ||
boolean isNullUnmarked = codeAnnotationInfo.isSymbolUnannotated(calledClass, config, handler); | ||
|
||
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. Let's move this code under the Also, it seems to me this logic could be simpler. If |
||
if (config.isJSpecifyMode()) { | ||
GenericsChecks.checkInstantiationForParameterizedTypedTree( | ||
tree, state, this, config, handler); | ||
isNullUnmarked, tree, state, this, config, handler); | ||
} | ||
return Description.NO_MATCH; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1737,6 +1737,33 @@ public void testRawTypeReceiverCast() { | |
.doTest(); | ||
} | ||
|
||
@Test | ||
public void testUseOfUnannotatedCode() { | ||
makeHelper() | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import org.jspecify.annotations.NullMarked;", | ||
"import org.jspecify.annotations.NullUnmarked;", | ||
"import org.jspecify.annotations.Nullable;", | ||
"class Test {", | ||
" @NullUnmarked", | ||
" static class nullUnmarkedClass<S> {", | ||
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. In Java, class names should start with a capital letter: https://google.github.io/styleguide/javaguide.html#s5.2.2-class-names |
||
" static <T> void m1(T t) {}", | ||
" }", | ||
" @NullMarked", | ||
" static class markedClass {", | ||
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. Again class name should start with capital letter |
||
" static void testInstantiation() {", | ||
" new nullUnmarkedClass<@Nullable String>();", | ||
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. Let's add a comment here (within quotes) indicating that despite the type variable not having a |
||
" }", | ||
" static void testAssignment() {", | ||
" nullUnmarkedClass<@Nullable Integer> var = null;", | ||
" }", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
public void boxInteger() { | ||
makeHelper() | ||
.addSourceLines( | ||
|
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.
remove this extra newline