Copilot commented on code in PR #12860:
URL: https://github.com/apache/cloudstack/pull/12860#discussion_r2961148528
##########
plugins/network-elements/ovs/src/main/java/com/cloud/network/ovs/OvsTunnelManagerImpl.java:
##########
@@ -171,17 +171,31 @@ protected OvsTunnelInterfaceVO
createInterfaceRecord(String ip,
}
private String handleFetchInterfaceAnswer(Answer[] answers, Long hostId) {
- OvsFetchInterfaceAnswer ans = (OvsFetchInterfaceAnswer)answers[0];
+ if (answers == null || answers.length == 0 || answers[0] == null) {
+ logger.warn("No answer returned for OvsFetchInterfaceCommand from
host " + hostId);
+ return null;
+ }
+
+ Answer answer = answers[0];
+
+ if (!(answer instanceof OvsFetchInterfaceAnswer)) {
+ logger.warn("Expected OvsFetchInterfaceAnswer from host " + hostId
+
+ " but got " + answer.getClass().getSimpleName() +
+ " with details: " + answer.getDetails());
+ return null;
+ }
+
+ OvsFetchInterfaceAnswer ans = (OvsFetchInterfaceAnswer) answer;
+
if (ans.getResult()) {
- if (ans.getIp() != null && !("".equals(ans.getIp()))) {
+ if (ans.getIp() != null && !ans.getIp().isEmpty()) {
OvsTunnelInterfaceVO ti = createInterfaceRecord(ans.getIp(),
- ans.getNetmask(), ans.getMac(), hostId,
ans.getLabel());
+ ans.getNetmask(), ans.getMac(), hostId, ans.getLabel());
return ti.getIp();
Review Comment:
`createInterfaceRecord(...)` can return null (e.g., lock acquisition failure
or `EntityExistsException` leaves `ti` null). Returning `ti.getIp()` here can
throw an NPE even when the agent successfully returned an IP. Consider handling
`ti == null` explicitly (e.g., log and return `ans.getIp()` or return null) to
avoid failing tunnel setup after a successful fetch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]