Skip to content

Conversation

@Zenith1415
Copy link
Contributor

@Zenith1415 Zenith1415 commented Dec 6, 2025

Fixes #17611

Description

Fixes a "NullPointerException" in "ReverseBuildTrigger" when the upstream threshold is null.

As noted in the discussion, "Result.isBetterOrEqualTo" contract requires a non-null parameter. Instead of modifying the core "Result" class, this patch adds a safety check in "ReverseBuildTrigger.shouldTrigger". If "threshold" is null , it now defaults to "Result.SUCCESS" to prevent the crash.

Testing done

  • Validated that "ReverseBuildTrigger.shouldTrigger" no longer passes "null" to "Result.isBetterOrEqualTo".
  • Verified code compilation with "mvn install -pl core".
  • Added automated test that shows the problem before the change and confirms the change fixes the problem

Proposed changelog entries

  • Fix NullPointerException in "ReverseBuildTrigger" when configuration has a missing threshold.

Proposed changelog category

/label bug

Proposed upgrade guidelines

N/A

Submitter checklist

  • The issue, if it exists, is well-described.
  • The changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developers, depending on the change) and are in the imperative mood.
  • There is automated testing or an explanation as to why this change has no tests.
  • New public classes, fields, and methods are annotated with @Restricted or have @since TODO Javadocs, as appropriate.
  • New deprecations are annotated with @Deprecated(since = "TODO") or @Deprecated(forRemoval = true, since = "TODO"), if applicable.
  • UI changes do not introduce regressions when enforcing the current default rules of Content Security Policy Plugin.
  • For dependency updates, there are links to external changelogs and, if possible, full differentials.
  • For new APIs and extension points, there is a link to at least one consumer.

Desired reviewers

@jenkinsci/core-pr-reviewers

Maintainer checklist

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title.
  • If it would make sense to backport the change to LTS, be a Bug or Improvement, and either the issue or pull request must be labeled as lts-candidate to be considered.

Copilot AI review requested due to automatic review settings December 6, 2025 17:39
@Zenith1415
Copy link
Contributor Author

/label bug

@comment-ops-bot comment-ops-bot bot added the bug For changelog: Minor bug. Will be listed after features label Dec 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a NullPointerException in Result.fromString() that occurs when the method receives a null input, as reported in JENKINS-39044. The fix adds a null check to return FAILURE immediately if the input is null.

Key Changes:

  • Removed @NonNull annotation from the fromString() method parameter
  • Added null check that returns FAILURE for null inputs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@daniel-beck
Copy link
Member

You're changing a complete different method than indicated in the stack trace. Please explain why. Were you able to reproduce the reported issue and encounter a different error? If so, what are the current steps to reproduce this? If not, what gives you any confidence that this change is useful?

Also, please do not delete the PR template, it exists for a reason.

@Zenith1415
Copy link
Contributor Author

Zenith1415 commented Dec 6, 2025

Thank you for the review! @daniel-beck
I apologize for deleting the PR template, I will restore it immediately.

Regarding the code change, I identified that fromString was not null-safe and looked like a potential cause, but I admit I haven't reproduced the exact stack trace locally yet. I will go back, reproduce the specific crash reported in the issue, and ensure my fix targets the correct method. I'll update the PR shortly.

@Zenith1415 Zenith1415 force-pushed the fix-npe-upstream-jobs branch from 320d93a to b7d6a94 Compare December 6, 2025 18:38
@Zenith1415
Copy link
Contributor Author

Zenith1415 commented Dec 6, 2025

Thanks for the review! Once again
You were absolutely right, I re-examined the stack trace from the issue ticket and confirmed the NPE is indeed occurring in "isBetterOrEqualTo", not "fromString".

I have updated the PR to:

  1. Revert the changes to "fromString".
  2. Apply the null-check fix to "isBetterOrEqualTo" instead.
  3. Add a JUnit 5 test case "ResultTest.java" that reproduces the null check and verifies the fix.

Ready for re-review. @daniel-beck

@mawinter69
Copy link
Contributor

Is this the right approach? The parameter was originally annotated with @NonNull. So it would be the callers job (ReverseBuildTrigger) to ensure that no null value is passed.
And why then only change that one comparison method? The same problem could occur on the other 3 methods as well.
And as @daniel-beck already asked have you tried to reproduce the error mentioned in the ticket? The sample-pipeline.xml looks as if it is properly configured, so if that still leads to a null value for the threshold, the solution is not to change the comparison method but fix the ReverseBuildTrigger.

Also note that we no longer use Jira ticket. Please refer to issue #17611 and adjust the title.

@timja timja changed the title (JENKINS-39044) Fix NPE in Result.fromString when upstream job result is null Fix NPE in Result.fromString when upstream job result is null Dec 6, 2025
@Zenith1415 Zenith1415 changed the title Fix NPE in Result.fromString when upstream job result is null Fix NPE in ReverseBuildTrigger due to null upstream threshold (Fixes #17611) Dec 7, 2025
@Zenith1415
Copy link
Contributor Author

@mawinter69 Thanks for the correction!

You made a very valid point regarding the "@nonnull" contract on "Result". I cured the symptom, but not the disease.
I will revert the changes to "Result.java" and instead investigate "ReverseBuildTrigger" to ensure it never passes a null threshold in the first place. I'll reproduce the issue locally using the sample pipeline config provided in #17611.
Updating the PR title now.

@Zenith1415 Zenith1415 force-pushed the fix-npe-upstream-jobs branch from b7d6a94 to d147200 Compare December 7, 2025 04:11
@Zenith1415
Copy link
Contributor Author

@mawinter69
I have updated the PR based on your feedback.

  1. Reverted changes done to "Result.java".
  2. Applied the fix directly in "ReverseBuildTrigger.java" by defaulting to "Result.SUCCESS" if the threshold is null.
  3. Updated the PR title and description.
    Ready for review.

@Zenith1415 Zenith1415 force-pushed the fix-npe-upstream-jobs branch from d147200 to a66a7b0 Compare December 7, 2025 15:18
@mawinter69
Copy link
Contributor

This will also fix #17725

@Zenith1415
Copy link
Contributor Author

Very Sorry Guys, I was a little inactive cause of some university's projects, tests and all
finally i'm almost done and yeah i reproduced the error in my local environment, as you asked @daniel-beck
image
And i tried my fix also, it fixes this properly!!
and thanks to point out, that it is eventually fixing some other issues also, though i haven't gone through that issue throughly for now, i'll do that as soon as possible @mawinter69

@mawinter69
Copy link
Contributor

Can you provide the steps how to reproduce the NPE

@Zenith1415
Copy link
Contributor Author

Sure! @mawinter69
I modified reversebuildtrigger.java such that it forces threshold = null, before the IsBetterOrEqualto check, then I ran a upstream job, which immediately triggered the NPE

@Zenith1415
Copy link
Contributor Author

Zenith1415 commented Dec 13, 2025

@jenkinsci/core-pr-reviewers , @daniel-beck, gentle ping

Has the same result as the deprecated constructor that was used before.
If the ReverseTrigger threshold were null, a null pointer exception would
be thrown.  The config round trip operation resets a null threshold to
SUCCESS, so this test reaches inside the job definition and changes the
threshold directly.

Testing done:

* Confirmed that the modified automated test fails when the change to
  ReverseTrigger is removed.
* Confirmed that the modified automated test passes when the change to
  ReverseTrigger is included.
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've extended an existing automated test to cover this fix. Thanks for the pull request!

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.

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback.

/label ready-for-merge

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Dec 14, 2025
@MarkEWaite MarkEWaite added the squash-merge-me Unclean or useless commit history, should be merged only with squash-merge label Dec 14, 2025
@MarkEWaite MarkEWaite requested a review from Copilot December 14, 2025 13:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MarkEWaite MarkEWaite changed the title Fix NPE in ReverseBuildTrigger due to null upstream threshold (Fixes #17611) Fix NPE in ReverseBuildTrigger due to null upstream threshold Dec 14, 2025
@MarkEWaite MarkEWaite merged commit 15263a6 into jenkinsci:master Dec 15, 2025
17 checks passed
@welcome
Copy link

welcome bot commented Dec 15, 2025

Congratulations on getting your very first Jenkins core pull request merged 🎉🥳

This is a fantastic achievement, and we're thrilled to have you as part of our community! Thank you for your valuable input, and we look forward to seeing more of your contributions in the future!

We would like to invite you to join the community chats and forums to meet other Jenkins contributors 😊
Don't forget to check out the participation page to learn more about how to contribute to Jenkins.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback squash-merge-me Unclean or useless commit history, should be merged only with squash-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-39044] NPE thrown when firing upstream jobs

5 participants