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

[JENKINS-60884] - Fix NPE in Run API when using getPreviousBuildsOverThreshold #4471

Merged
merged 3 commits into from
Feb 5, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,10 @@ protected void dropLinks() {
*/
public @Nonnull List<RunT> getPreviousBuildsOverThreshold(int numberOfBuilds, @Nonnull Result threshold) {
RunT r = getPreviousBuild();
return r.getBuildsOverThreshold(numberOfBuilds, threshold);
if( r!=null ) {
AaronZurawski marked this conversation as resolved.
Show resolved Hide resolved
return r.getBuildsOverThreshold(numberOfBuilds, threshold);
}
return new ArrayList<>(numberOfBuilds);
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT-Non-blocking: Probably makes more sense for it to have no initial capacity

Suggested change
return new ArrayList<>(numberOfBuilds);
return new ArrayList<>();

Copy link
Contributor Author

@AaronZurawski AaronZurawski Feb 4, 2020

Choose a reason for hiding this comment

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

I agree but I chose to give it a capacity as this is what it would have returned in this case before being refactored.

My thought was to not change behavior no matter how insignificant. I can commit this suggestion if you still would recommend it after my comment.

}

/**
Expand Down