Skip to content

Added numeric getById to RunMap and deprecate String API#26096

Open
somiljain2006 wants to merge 17 commits intojenkinsci:masterfrom
somiljain2006:Runmap-issue
Open

Added numeric getById to RunMap and deprecate String API#26096
somiljain2006 wants to merge 17 commits intojenkinsci:masterfrom
somiljain2006:Runmap-issue

Conversation

@somiljain2006
Copy link
Contributor

@somiljain2006 somiljain2006 commented Jan 9, 2026

Fixes #16693

This change introduces a canonical getById(int) API and deprecates the legacy getById(String) overload. The String-based method is retained for backward compatibility and preserves behavior by returning null for non-numeric IDs instead of throwing an exception.

Testing done

  • Automated Tests:
    • Ran the Jenkins core test suite to verify the new RunMap#getById(int) API and getById(String) behavior.
    • Added and executed a regression test covering:
      1. successful lookup via the new int-based API
      2. backward-compatible lookup via numeric String IDs
      3. safe null return for non-numeric inputs
    • Verified that the deprecated getById(String) no longer throws NumberFormatException for invalid input.
    • Confirmed that all existing RunMapTest cases continue to pass without behavioral changes.
  • Interactive Testing:
    A Freestyle job with a completed build was created, and behavior was verified via the Script Console:
    • getById(int) successfully returns the build
    • getById(String) continues to work for numeric IDs
    • Non-numeric String IDs safely return null without throwing exceptions

Proposed changelog entries

  • Introduce a numeric RunMap#getById(int) API and deprecate the String-based overload.

Proposed changelog category

/label developer

Proposed upgrade guidelines

N/A

Desired reviewers

@jenkinsci/core-pr-reviewers, @daniel-beck, @MarkEWaite, @strangelookingnerd

Before the changes are marked as ready-for-merge:

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 (see example).
  • 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.

@comment-ops-bot comment-ops-bot bot added the developer Changes which impact plugin developers label Jan 9, 2026
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 pull request introduces a canonical numeric getById(int) API for RunMap and deprecates the legacy String-based getById(String) overload. The String-based method is retained for backward compatibility and gracefully handles non-numeric IDs by returning null instead of throwing an exception.

Changes:

  • Added new getById(int) method that delegates to getByNumber(int)
  • Deprecated existing getById(String) with enhanced error handling for non-numeric IDs
  • Added comprehensive test coverage for both legacy and new APIs
  • Minor improvements to test robustness and code quality (null safety checks, spelling corrections)

Reviewed changes

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

File Description
core/src/main/java/hudson/model/RunMap.java Introduces the new numeric getById(int) API and modifies the String-based overload to handle non-numeric IDs gracefully; includes minor documentation improvements (spelling corrections)
test/src/test/java/hudson/model/RunMapTest.java Adds comprehensive test coverage for both legacy String-based and new numeric getById methods; includes incidental null safety improvements in existing tests

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

Comment on lines +228 to +229
*
* @since TODO
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The @since tag is set to "TODO". This should be updated to the actual version number before merging. Please replace "TODO" with the appropriate Jenkins version number for this release.

Suggested change
*
* @since TODO

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@MarkEWaite MarkEWaite Jan 12, 2026

Choose a reason for hiding this comment

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

This comment by GitHub Copilot is incorrect. In the Jenkins project, we use @since TODO as a marker so that the release number can be updated after the first release that includes the new code.

It also would be much better if the markdown generated by GitHub Copilot used @since to show it is code, instead of referring to a GitHub user of that name. I corrected that mistake in the Copilot comment.

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.

Comment needs to revert back to the original value, at least as far as I can tell. It was correct and GitHub Copilot requested an incorrect change

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.

Please complete the "Testing done" section of the pull request template and describe how you tested this code interactively.

@somiljain2006
Copy link
Contributor Author

@MarkEWaite I’ve updated the Testing section of the PR.

*/
@CheckForNull
@Override public R getById(String id) {
public R getById(int id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

While I don't think there is anything wrong with this change I wonder why it's not implemented in the AbstractLazyLazyRunMap or we just point the deprecation notice to #getByNumber?

@jglick Since you mentioned this in #10456 (comment) - any suggestions from you here?

Copy link
Member

Choose a reason for hiding this comment

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

Dates to #1379.

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Does not actually seem to do the work of replacing the calls to the now-deprecated overload.

/**
* Suitable for {@link Job#getBuild}.
*/
public final RunT getBuild(String id) {
Copy link
Member

Choose a reason for hiding this comment

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

So why is this still using a String? The point is to get rid of all the gratuitous decimal parsing/formatting in the critical path, deprecating this stuff and leaving it as dead code.

Copy link
Contributor Author

@somiljain2006 somiljain2006 Feb 4, 2026

Choose a reason for hiding this comment

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

I agree. I have reverted the changes in LazyBuildMixIn and removed the redundant parsing logic, leaving it as a simple pass-through to the deprecated RunMap#getById(String).

I also searched the codebase for internal calls to getById(String), but I didn't find any other call sites in Core that need to be migrated. If there are specific call sites I missed, please let me know, and I will update them.

@somiljain2006 somiljain2006 requested a review from jglick February 4, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

developer Changes which impact plugin developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-75476] Deprecate hudson.model.RunMap#getById(String) in favor of an int parameter version

4 participants