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

Added a extra check in if condition to avoid null pointer exception #1651

Closed
wants to merge 4 commits into from

Conversation

AniketNS
Copy link
Contributor

@AniketNS AniketNS commented Apr 10, 2024

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 .

@AniketNS AniketNS requested a review from a team as a code owner April 10, 2024 10:15
Copy link
Contributor

@MarkEWaite MarkEWaite left a 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?

@MarkEWaite
Copy link
Contributor

Please complete the "Testing done" section of the pull request template. In that section, it says:

Provide a clear description of how this change was tested. At minimum this should include proof that a computer has executed the changed lines. Ideally this should include an automated test or an explanation as to why this change has no tests. Note that automated test coverage is less than complete, so a successful PR build does not necessarily imply that a computer has executed the changed lines. If automated test coverage does not exist for the lines you are changing, you must describe the scenario(s) in which you manually tested the change. For refactoring and code cleanup changes, exercise the code before and after the change and verify the behavior remains the same.

@AniketNS
Copy link
Contributor Author

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?

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.

@AniketNS
Copy link
Contributor Author

Please complete the "Testing done" section of the pull request template. In that section, it says:

Provide a clear description of how this change was tested. At minimum this should include proof that a computer has executed the changed lines. Ideally this should include an automated test or an explanation as to why this change has no tests. Note that automated test coverage is less than complete, so a successful PR build does not necessarily imply that a computer has executed the changed lines. If automated test coverage does not exist for the lines you are changing, you must describe the scenario(s) in which you manually tested the change. For refactoring and code cleanup changes, exercise the code before and after the change and verify the behavior remains the same.

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 mvn clean -DskipTests verify(without tests)? I haven't tested this new code. I was just going through the code and trying to understand it and spot this correction and thought should make a PR.

Can you please provide me with some more detail on what should I do?

@MarkEWaite
Copy link
Contributor

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.

@AniketNS
Copy link
Contributor Author

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.

@AniketNS
Copy link
Contributor Author

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.

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?

@krisstern krisstern added the wontfix This will not be worked on label Aug 28, 2024
@krisstern
Copy link
Member

Hi @AniketNS, when and where do you encounter a null pointer exception for src/main/java/com/dabsquared/gitlabjenkins/workflow/AcceptGitLabMergeRequestStep.java?

@MarkEWaite
Copy link
Contributor

Closing pull request due to no response. Can be reopened in the future if a response is received

@MarkEWaite MarkEWaite closed this Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants