Skip to content

LSP Server: Adding Null Checks in MoveRefactoring code action#7923

Merged
mbien merged 1 commit intoapache:masterfrom
shivam71:MoveRefactoring_Fix
Nov 7, 2024
Merged

LSP Server: Adding Null Checks in MoveRefactoring code action#7923
mbien merged 1 commit intoapache:masterfrom
shivam71:MoveRefactoring_Fix

Conversation

@shivam71
Copy link
Copy Markdown
Contributor

  • Initially when creating the refactoring web view the variables selectedProject and selectedRoot are NULL.
  • getPath method called on a null results in a null pointer exception .
  • Uncaught null pointer exception was leading to refactoring failing sometimes . Hence this fix is required .

@mbien
Copy link
Copy Markdown
Member

mbien commented Oct 30, 2024

catching NPEs isn't a good practice. This should be solved at the point where the NPE occurs if possible.

@mbien mbien added the LSP [ci] enable Language Server Protocol tests label Oct 30, 2024
@lahodaj
Copy link
Copy Markdown
Contributor

lahodaj commented Oct 31, 2024

catching NPEs isn't a good practice. This should be solved at the point where the NPE occurs if possible.

+1 - catching a NPE is almost always the bad solution. If something can validly be null, there should be a null check. If something is believed to not to be null, and it is null, the source that is incorrectly providing null should be fixed.

In this case, I have a question: if the selectedProject/selectedRoot are null, will this code be called again/the results be refreshed when they are set to non-null?

@shivam71
Copy link
Copy Markdown
Contributor Author

shivam71 commented Nov 4, 2024

Thanks @mbien and @lahodaj ! I will make the changes to check for null directly and handle it gracefully rather than catching the NPE. @lahodaj To answer your question yes this code will be called again when selectedProject/selectedRoot is non null or is changed .

@shivam71 shivam71 changed the title LSP Server: Catching NullPointer Exception in MoveRefactoring code action LSP Server: Adding Null Checks in MoveRefactoring code action Nov 4, 2024
@shivam71 shivam71 force-pushed the MoveRefactoring_Fix branch from 6d8a989 to 4380550 Compare November 4, 2024 04:44
@shivam71 shivam71 force-pushed the MoveRefactoring_Fix branch from 4380550 to 0bb6141 Compare November 7, 2024 07:41
Copy link
Copy Markdown
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

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

Looks better to me, thanks!

Copy link
Copy Markdown
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

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

thanks, tests are also green -> merging

@mbien mbien merged commit 7d89336 into apache:master Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LSP [ci] enable Language Server Protocol tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants