-
Notifications
You must be signed in to change notification settings - Fork 619
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
Added a extra check in if condition to avoid null pointer exception #1651
Conversation
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 still don't understand the logic or why it was added.
Previously, if the step was configured to not use the merge request description, then it would return the value of merge.CommitMessage.
In the new code, if the step was configured to not use the merge request description or if the merge commit message of the step is empty or null, then it would return the value of merge.CommitMessage.
I don't see how that extra condition avoids a null pointer exception. Can you more clearly describe the case where you've seen a null pointer exception?
Please complete the "Testing done" section of the pull request template. In that section, it says:
|
Oh, I'm so sorry @MarkEWaite, I forgot to add the condition "if mergeCommitMessage is not null". I just checked if it is null. Yeah, you are correct, "Previously, if the step was configured to not use the merge request description, then it would return the value of merge.CommitMessage." But what if the value of merge.CommitMessage is empty. It would just return an empty message. That's why I added a code to check if merge.CommitMessage is not null. And if the merge.CommitMessage is null then it won't return it. That's what I wanted to do. Correct me if I'm wrong. |
Sorry, I didn't understand @MarkEWaite, should I provide the screenshot that my computer has executed the changed lines that it has actually, with the command Can you please provide me with some more detail on what should I do? |
A common technique that I've used is to open my IDE, set a breakpoint on the modified line, then run automated tests from the debugger to confirm that the breakpoint is reached. If the breakpoint is reached, then that tells you the code is executed by automated tests. That also offers a hint of the test that might be extended or modified to test for the null pointer exception that you are trying to avoid. If the breakpoint is not reached by the automated tests, then I'll run Jenkins core and the plugin from a debugger, set a breakpoint on the modified line, and confirm that I can reach that breakpoint interactively. If the debugger and breakpoint method does not work for you, then you can always locally add logging statements that report when a line is executed. |
Thanks for the nice explanation. I'll try this and let you know. |
Hey @MarkEWaite, I was trying to perform debugging on the AcceptGitLabMergeRequestStep.java file. But, I got to know that there is no test file to debug this file and I cannot perform the debugging without a test file. Do I need to write the test file first or is there anything else I didn't understand? |
Hi @AniketNS, when and where do you encounter a null pointer exception for |
Closing pull request due to no response. Can be reopened in the future if a response is received |
Testing done
Submitter checklist
This change works fine in my machine when I run command
mvn clean -DskipTests verify
. The change is already discussed in PR #1646 .