Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts OpenShift build retrieval to safely handle missing BuildConfigs by returning null instead of throwing a NullPointerException, allowing build waiters to retry gracefully. Sequence diagram for OpenShift build waiter handling missing BuildConfigsequenceDiagram
actor Tester
participant OpenshiftWaiters
participant OpenShift
participant OpenShiftClient
Tester->>OpenshiftWaiters: hasBuildCompleted(buildConfigName)
OpenshiftWaiters->>OpenShift: getLatestBuild(buildConfigName)
OpenShift->>OpenShiftClient: buildConfigs().withName(buildConfigName).get()
OpenShiftClient-->>OpenShift: BuildConfig or null
alt BuildConfig is null
OpenShift-->>OpenshiftWaiters: null
OpenshiftWaiters->>OpenshiftWaiters: wait and retry
else BuildConfig exists
OpenShift->>OpenShift: lastVersion = bc.getStatus().getLastVersion()
OpenShift->>OpenShift: buildName = buildConfigName + '-' + lastVersion
OpenShift->>OpenShiftClient: getBuild(buildName)
OpenShiftClient-->>OpenShift: Build
OpenShift-->>OpenshiftWaiters: Build
OpenshiftWaiters->>OpenshiftWaiters: evaluate completion
end
Updated class diagram for OpenShift getLatestBuild behaviorclassDiagram
class OpenShift {
+Build getBuild(String name)
+Build getLatestBuild(String buildConfigName)
}
class BuildConfig {
+BuildConfigStatus getStatus()
}
class BuildConfigStatus {
+long getLastVersion()
}
class Build {
}
OpenShift --> BuildConfig : queries
BuildConfig --> BuildConfigStatus : has
OpenShift --> Build : returns
note for OpenShift "getLatestBuild:
1. BuildConfig bc = buildConfigs().withName(buildConfigName).get()
2. if bc == null return null
3. long lastVersion = bc.getStatus().getLastVersion()
4. return getBuild(buildConfigName + '-' + lastVersion)"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The NPE fix only guards against a null BuildConfig; if
bc.getStatus()can also be null in the slow-reconciliation scenario, you may want to null-checkbc.getStatus()before dereferencinggetLastVersion()to fully address the issue.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The NPE fix only guards against a null BuildConfig; if `bc.getStatus()` can also be null in the slow-reconciliation scenario, you may want to null-check `bc.getStatus()` before dereferencing `getLastVersion()` to fully address the issue.
## Individual Comments
### Comment 1
<location path="core/src/main/java/cz/xtf/core/openshift/OpenShift.java" line_range="835-839" />
<code_context>
public Build getLatestBuild(String buildConfigName) {
- long lastVersion = buildConfigs().withName(buildConfigName).get().getStatus().getLastVersion();
+ BuildConfig bc = buildConfigs().withName(buildConfigName).get();
+ if (bc == null) {
+ return null;
+ }
+ long lastVersion = bc.getStatus().getLastVersion();
return getBuild(buildConfigName + "-" + lastVersion);
}
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against a null BuildConfig status before calling getLastVersion()
The null check on `bc` prevents one NPE, but `bc.getStatus()` itself can still be null (e.g., for a newly created/partially initialized BuildConfig), causing an NPE on `getStatus().getLastVersion()`. Please also guard against a null status (and optionally handle a 0/unset `getLastVersion()`) before building the name, or fail in a controlled way.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| BuildConfig bc = buildConfigs().withName(buildConfigName).get(); | ||
| if (bc == null) { | ||
| return null; | ||
| } | ||
| long lastVersion = bc.getStatus().getLastVersion(); |
There was a problem hiding this comment.
issue (bug_risk): Guard against a null BuildConfig status before calling getLastVersion()
The null check on bc prevents one NPE, but bc.getStatus() itself can still be null (e.g., for a newly created/partially initialized BuildConfig), causing an NPE on getStatus().getLastVersion(). Please also guard against a null status (and optionally handle a 0/unset getLastVersion()) before building the name, or fail in a controlled way.
There was a problem hiding this comment.
Pull request overview
Adjusts OpenShift build lookup to avoid crashing when the BuildConfig isn’t available yet, allowing OpenShiftWaiters.hasBuildCompleted to keep retrying in slow/reconciling environments.
Changes:
- Update
OpenShift.getLatestBuildto returnnullwhen theBuildConfigcannot be fetched.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| if (bc == null) { | ||
| return null; | ||
| } | ||
| long lastVersion = bc.getStatus().getLastVersion(); |
There was a problem hiding this comment.
getLatestBuild still has a possible NPE: bc.getStatus() can be null (and in this codebase getLastVersion() is treated as nullable elsewhere), so bc.getStatus().getLastVersion() may crash even when bc is non-null. Consider returning null when bc.getStatus() is null and when getLastVersion() is null/0 (use Long instead of long) so waiters can retry gracefully.
| long lastVersion = bc.getStatus().getLastVersion(); | |
| if (bc.getStatus() == null) { | |
| return null; | |
| } | |
| Long lastVersion = bc.getStatus().getLastVersion(); | |
| if (lastVersion == null || lastVersion == 0L) { | |
| return null; | |
| } |
|
LGTM, merging. Thanks |
Return null instead of crashing so
OpenshiftWaiters.hasBuildCompletedcan retry gracefully. Reproduces on slower environments where Helm chart reconciliation lags behind the waiter start.Closes #641
Summary by Sourcery
Bug Fixes: