-
Notifications
You must be signed in to change notification settings - Fork 917
solves NPE in RemoveUnnecessary.java #8575
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
Conversation
mbien
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.
I had a note in my stash to find a reproducer for this - but never ended up finding one. But I agree we should add a defensive check there to prevent the NPE.
java/java.hints/src/org/netbeans/modules/java/hints/control/RemoveUnnecessary.java
Show resolved
Hide resolved
|
I am sorry, but this is not right. I don't think the leaf can be
|
|
I should have saved the error message that NetBeans produced via a bulb at the bottom status line. If null is an acceptable return value for the method, then the suggestion by mbien is probably the better one. I chose to follow the pattern inside the case labels which tend to continue the loop. netbeans/java/java.hints/src/org/netbeans/modules/java/hints/control/RemoveUnnecessary.java Lines 108 to 134 in 049b5ed
|
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.
please add the testcase @lahodaj posted in #8575 (comment) to RemoveUnnecessaryTest
edit: feel free to squash and force push
java/java.hints/src/org/netbeans/modules/java/hints/control/RemoveUnnecessary.java
Outdated
Show resolved
Hide resolved
Your test points exactly at the culprit, it becomes red, the true colour of a useful test, when I comment the solution out. Thanks mbien and lahodaj. |
5d0c99c to
1f0eac4
Compare
|
I should pay better attention when squashing ;-(( |
@homberghp can you run this line on your local branch: This will remove all merge commits and move your commit on top of everything. then you force push into this PR: now your PR should only contain one commit with your changes |
|
thank you, I needed that hint. |
…trol/RemoveUnnecessary.java The NPE is thrown in java/java.hints/src/org/netbeans/modules/java/hints/control/RemoveUnnecessary.java:117, tp.getLeaf().getKind() does not verify that the return value of tp.getLeaf() is non-null; The solution tests for non-null-ness and return null if tp==null Added test as suggensted by lahodaj.
c925df8 to
5356c07
Compare
|
As far as git is concerned I am still a newcomer, but thankfully I have good and patient teachers. |
no worries. Many other projects don't require to squash before merge because the committer who integrates would squash using github. But there were problems with that in past, so we decided to merge commits as-is. |
mbien
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.
looks good. @lahodaj thanks for the reproducer and the help.
will merge once CI is green
lahodaj
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.
Looks good to me.
The NPE is thrown in java/java.hints/src/org/netbeans/modules/java/hints/control/RemoveUnnecessary.java:117, tp.getLeaf().getKind() does not verify that the return value of tp.getLeaf() is non-null;
The solution tests for non-null-ness and continues the while loop if the return value is null, thereby avoiding the NPE and continuing with the next iteration in the while loop.
^Add meaningful description above
Click to collapse/expand PR instructions
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
Please make sure (eg.
git log) that all commits have a valid name and email address for you in the Author field.If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
PR approval and merge checklist:
If this PR targets the delivery branch: don't merge. (full wiki article)