Skip to content
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

fix: Fix NullPointerException when allowing duplicate classes #3709

Conversation

slarse
Copy link
Collaborator

@slarse slarse commented Nov 24, 2020

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 with JDTTreeBuilderQuery::searchTypeBinding, in which a NullPointerException would occur if there was a duplicated class that was processed before finding the sought type. The reason is that a duplicated class will have binding = 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, and Main is type A. There is also a duplicated class Duplicated.

Fixing the bug was trivial, replicating it was hard :)

@slarse slarse changed the title wip: fix: Fix NullPointerException when allowing duplicate classes review: fix: Fix NullPointerException when allowing duplicate classes Nov 24, 2020
@monperrus
Copy link
Collaborator

Thanks a lot @slarse LGTM, will merge

@monperrus monperrus changed the title review: fix: Fix NullPointerException when allowing duplicate classes fix: Fix NullPointerException when allowing duplicate classes Nov 26, 2020
@monperrus monperrus merged commit 2330008 into INRIA:master Nov 26, 2020
@slarse slarse deleted the issue/3707-fix-crash-on-parse-with-ignore-duplicates branch December 9, 2020 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Crash when parsing RDF4J with "ignore duplicate declarations"
2 participants