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

PreconditionsChecker: fixed NPE when path is null. #5346

Merged
merged 1 commit into from
Jan 24, 2023

Conversation

mbien
Copy link
Member

@mbien mbien commented Jan 23, 2023

fixes #5202, targets delivery

java.lang.NullPointerException: Cannot invoke "com.sun.source.util.TreePath.getLeaf()" because "path" is null
	at org.netbeans.lib.nbjavac.services.NBJavacTrees.getElement(NBJavacTrees.java:66)
	at org.netbeans.lib.nbjavac.services.NBJavacTrees.getElement(NBJavacTrees.java:40)
	at org.netbeans.modules.java.hints.jdk.mapreduce.PreconditionsChecker$VariablesVisitor.isLocalVariable(PreconditionsChecker.java:226)

JavacTrees and NBJavacTrees don't accept null as path parameters in the getElement method, so we guard against it and return false.

@mbien mbien added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) hints labels Jan 23, 2023
@mbien mbien added this to the NB17 milestone Jan 23, 2023
@mbien mbien linked an issue Jan 23, 2023 that may be closed by this pull request
@mbien mbien requested a review from lkishalmi January 23, 2023 13:38
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really familiar with the code in question, but given, that this method already handles getElement returning null, checking the path prior seems reasonable.

Copy link
Contributor

@lkishalmi lkishalmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Thanks!

@neilcsmith-net neilcsmith-net merged commit 366e0de into apache:delivery Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hints Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE in Java hints PreconditionsChecker.java line 226
4 participants