-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add guardrails to prevent and correct wrong output from JavaTypeCorrect #339
Conversation
… try-with-resources
… try-with-resources
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.
Looks good to me, aside from one minor comment!
@@ -104,6 +107,24 @@ public Map<String, String> getClassAndUnresolvedInterface() { | |||
* @return the map described above. | |||
*/ | |||
public Map<String, String> getExtendedTypes() { | |||
// Before returning, purge any entries that are obviously bad according to | |||
// the following simple heuristic(s): | |||
// * don't extend known-final classes from the JDK, like java.lang.String. |
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.
This comment sounds like java.lang.String
isn't the only known-final class in the JDK, but the code below only includes that case. Are there supposed to be more or should this comment be adjusted for clarity?
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.
I thought we might want to add more in the future, so I future-proofed the comment. Your point is a good one, though - what we should do is look up a list, and then add that to JavaLangUtils
. I'll do that now.
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.
LGTM, one small comment change.
Incorporates #338, so don't review until that is merged.I'm not sure if we want to merge this. It avoids some bad behavior on the NA-176 test, and we could probably expand it in the future for other, similar kinds of problems. However, it definitely does not address the root cause: why is Specimin putting itself in a situation where javac insists that a synthetic class must be compatible with String?I'm going to continue my investigation, but I'm leaving this PR here because I may want to merge it later if the fix for the root cause is too complex and/or impracticle.This PR makes a series of changes to how our javac type correction algorithm (in the
JavaTypeCorrect
class) handles complex cases. That algorithm is fundamentally imprecise, so the changes in this PR should be thought of as incremental improvements to the existing design that avoid some of its worst pathologies. In particular, this PR:java.lang.String
, which is final;SyntheticUnconstrainedType
type variable to propagate beyond the return type to which it is applied; and,SyntheticUnconstrainedType
withjava.lang.Object
. Previously, these types would hang around and make the output non-compilable, since they'd been marked as unused.Together, these changes make NullAway-176 reproducible, based on my local testing.