-
Notifications
You must be signed in to change notification settings - Fork 13
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
Avoid reading type info from trees that are not being processed #385
Avoid reading type info from trees that are not being processed #385
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.
Thanks! I've a questions, but overall this looks good.
@@ -90,6 +92,15 @@ protected Factory createTypeFactory() { | |||
return (Factory)((BaseInferrableChecker)checker).getTypeFactory(); | |||
} | |||
|
|||
@Override | |||
public void visit(TreePath path) { |
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.
Documentation from its super class:
Entry point for a type processor: the TreePath leaf is a top-level type tree within root.
And this is why I choose to call slotManager.setTopLevelClass
from here.
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.
Thanks!
Currently, all checkers in inference may crash on the following code:
This is because
AbstractTypeProcessor::typeProcess
only receives one fully-analyzed top-level class at a time, whileSlotDefaultTypeResolver
tries to compute the default types for the entire compilation unit. Details about the crash:AbstractTypeProcessor
) receives a call to type process the top-level classVectorTest
.Vector
is also under the same compilatioon unit tree, some of its fields in the internalJCTree
implementation are not yet initialized (they are null).SlotDefaultTypeResolver
receives a call to find the default types for the entire compilation unit tree, and it will visit all type trees in the classVector
.SlotDefaultTypeResolver
hitsint aLength
inVector::max
, it tries to get the ATM ofint
by callingrealTypeFactory.getAnnotatedTypeFromTypeTree
.AnnotatedTypeFactory::type(Tree node)
, in which we try to fetch theTypeMirror
of this primitive type tree.TypeMirror
we get from javac is always null. So the program crashses.To fix this issue, this PR introduces the following changes:
getCurrentTopLevelClass()
toInferenceChecker
so we can determine whether a tree is outside of the current processing scope.SlotDefaultTypeResolver
no longer process the entire compilation unit tree.The test case has already been introduced in PR #381