-
Notifications
You must be signed in to change notification settings - Fork 13
Avoid reading type info from trees that are not being processed #385
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
Conversation
wmdietl
left a comment
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.
| } | ||
|
|
||
| @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.
wmdietl
left a comment
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::typeProcessonly receives one fully-analyzed top-level class at a time, whileSlotDefaultTypeResolvertries 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.Vectoris also under the same compilatioon unit tree, some of its fields in the internalJCTreeimplementation are not yet initialized (they are null).SlotDefaultTypeResolverreceives a call to find the default types for the entire compilation unit tree, and it will visit all type trees in the classVector.SlotDefaultTypeResolverhitsint aLengthinVector::max, it tries to get the ATM ofintby callingrealTypeFactory.getAnnotatedTypeFromTypeTree.AnnotatedTypeFactory::type(Tree node), in which we try to fetch theTypeMirrorof this primitive type tree.TypeMirrorwe get from javac is always null. So the program crashses.To fix this issue, this PR introduces the following changes:
getCurrentTopLevelClass()toInferenceCheckerso we can determine whether a tree is outside of the current processing scope.SlotDefaultTypeResolverno longer process the entire compilation unit tree.The test case has already been introduced in PR #381