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

Prevent null pointer exceptions in NextLabelCause #372

Conversation

MarkEWaite
Copy link
Contributor

@MarkEWaite MarkEWaite commented Dec 24, 2024

Prevent null pointer exceptions in NextLabelCause

The equals method and the hashCode method both would throw a null pointer exception if the label in the constructor was null. I doubt that the label in the constructor has ever been null, but it is easy to safeguard those two methods so that they are null-safe.

The test code incorrectly tested the equals contract of the wrong class due to my copy and paste error. Test the correct class.

Uses the simple() verifier because the UpstreamCause class seems to have complications related to its superclass and I'd rather not spend the time to investigate further. The simple() verifier detected the null pointer exceptions, so it is still better than not testing.

Special thanks to @code-arnab for detecting and reporting the mistake in #371 (comment)

Testing done

Automated tests pass locally on Linux. Rely on ci.jenkins.io to test Windows.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

The equals method and the hashCode method both would throw a null pointer
exception if the label in the constructor was null.  I doubt that the
label in the constructor has ever been null, but it is easy to safeguard
those two methods so that they are null-safe.
@MarkEWaite MarkEWaite added the bug Incorrect or flawed behavior label Dec 24, 2024
@MarkEWaite MarkEWaite requested a review from a team as a code owner December 24, 2024 12:57
@github-actions github-actions bot added the tests Automated test addition or improvement label Dec 24, 2024
The code incorrectly tested the equals contract of the wrong class due
to my copy and paste error.  Test the correct class.

Uses the simple() verifier because the UpstreamCause class seems to
have complications related to its superclass and I'd rather not spend
the time to investigate further.  The simple() verifier detected the
null pointer exceptions, so it is still better than not testing.

Removes temporary check for null pointers, since equalsverifier performs
the same checks.
@MarkEWaite MarkEWaite force-pushed the fix-NPE-in-NextLabelCause-equals-and-hashCode branch from 8f91695 to 936cc16 Compare December 24, 2024 12:58
@MarkEWaite MarkEWaite removed the tests Automated test addition or improvement label Dec 24, 2024
@code-arnab
Copy link
Contributor

Prevent null pointer exceptions in NextLabelCause

The equals method and the hashCode method both would throw a null pointer exception if the label in the constructor was null. I doubt that the label in the constructor has ever been null, but it is easy to safeguard those two methods so that they are null-safe.

The code incorrectly tested the equals contract of the wrong class due to my copy and paste error. Test the correct class.

Uses the simple() verifier because the UpstreamCause class seems to have complications related to its superclass and I'd rather not spend the time to investigate further. The simple() verifier detected the null pointer exceptions, so it is still better than not testing.

Special thanks to @code-arnab for detecting and reporting the mistake in #371 (comment)

Testing done

Automated tests pass locally on Linux. Rely on ci.jenkins.io to test Windows.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

Thank You and Great work @MarkEWaite

@MarkEWaite MarkEWaite merged commit d1abf29 into jenkinsci:master Dec 24, 2024
18 checks passed
@MarkEWaite MarkEWaite deleted the fix-NPE-in-NextLabelCause-equals-and-hashCode branch December 24, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect or flawed behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants