-
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
Properly check generic method overriding in explicitly-typed anonymous classes #808
Properly check generic method overriding in explicitly-typed anonymous classes #808
Conversation
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.
Sorry it took so long. One initial pass here. Overall, it looks good.
" public @Nullable String apply(String s) { return null; }", | ||
" };", | ||
" FnClass<String, @Nullable String> fn4 = new FnClass<String, @Nullable String>() {", | ||
" public @Nullable String apply(String s) { return 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.
Why are both true positive cases on the parameter and both true negatives on the return value? Seems like it might test more combinations to do one each?
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.
if (newClassTree == null) { | ||
throw new RuntimeException( | ||
"method should be inside a NewClassTree " + state.getSourceForNode(path.getLeaf())); | ||
} |
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.
Do we want a check that the NewClassTree
is for the same type as symbol
['s supertype]? Or can that be safely assumed to never break?
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 we add a test case for when the class name is given as something other than a simple name? new Foo.Builder<@Nullable String>() { ... }
or even new Foo<@Nullable String>.Builder() {...}
?
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.
Do we want a check that the
NewClassTree
is for the same type assymbol
['s supertype]? Or can that be safely assumed to never break?
I added a check in af6ca1f; can't hurt :-)
Can we add a test case for when the class name is given as something other than a simple name?
new Foo.Builder<@Nullable String>() { ... }
or evennew Foo<@Nullable String>.Builder() {...}
?
I added some tests in 16eb9c2 but one of them is failing (see overrideAnonymousNestedClass()
) 😐 I propose I fix that issue in a follow-up; does that sound ok?
…m/msridhar/NullAway into override-anonymous-class-checking
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #808 +/- ##
============================================
- Coverage 86.79% 86.75% -0.05%
- Complexity 1870 1876 +6
============================================
Files 74 74
Lines 6178 6197 +19
Branches 1202 1206 +4
============================================
+ Hits 5362 5376 +14
- Misses 405 408 +3
- Partials 411 413 +2
☔ View full report in Codecov by Sentry. |
@lazaroclapp I finally got around to addressing your feedback here; sorry for the long delay. |
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.
See minor comment above, but otherwise SGTM!
.doTest(); | ||
} | ||
|
||
@Ignore("Need to add support for this case") |
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.
Let's create and link an issue!
This completes a task lingering from #755, which did not handle overriding in anonymous classes. This case is slightly tricky as javac does not preserve annotations on type arguments in the types it computes for anonymous classes. To fix, we pass a
Symbol
where we were passing aType
in a couple places, as then we can callSymbol.isAnonymous()
to check for an anonymous type. In such a case, we try to get the type from the enclosingNewClassTree
of the overriding method. Note that this PR still does not handle anonymous classes that use the diamond operator; we add a test to show the gaps.