fix: Fix NullPointerException when allowing duplicate classes #3709
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #3707
This crash occurs very rarely. The requirement is that there is a package private class B with a nested type C, and have some other class A import B.C and then make an unqualified access to some member C.someMember. At the samie time, there must be a duplicated class in the same package and
setIgnoreDuplicateDeclarations(true)
must be active. The import + access in type A forces Spoon to search for type C withJDTTreeBuilderQuery::searchTypeBinding
, in which aNullPointerException
would occur if there was a duplicated class that was processed before finding the sought type. The reason is that a duplicated class will havebinding = null
.This does not happen if Spoon is not ignoring duplicates, because then an appropriate error on finding duplicate declarations is raised much earlier.
In the test case provided with this PR,
WithNestedEnum
is type B,NestedEnum
is type C, andMain
is type A. There is also a duplicated classDuplicated
.Fixing the bug was trivial, replicating it was hard :)