Copilot commented on code in PR #13775:
URL: https://github.com/apache/cloudstack/pull/13775#discussion_r3705586614


##########
engine/components-api/src/main/java/com/cloud/alert/AlertFormatUtils.java:
##########
@@ -0,0 +1,39 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.alert;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.Pod;
+import com.cloud.host.Host;
+
+/**
+ * Shared formatting for the host/zone/pod description that recurs, 
independently
+ * hand-rolled and inconsistently worded (and occasionally mislabelled), 
across the
+ * HA and agent-management alert call sites. See CLOUDSTACK-7297.
+ */
+public final class AlertFormatUtils {
+
+    private AlertFormatUtils() {
+    }
+
+    public static String describeHostLocation(Host host, DataCenter zone, Pod 
pod) {
+        return String.format("name: %s (id: %d, uuid: %s), availability zone: 
%s, pod: %s",
+                host.getName(), host.getId(), host.getUuid(),
+                zone != null ? zone.getName() : "unknown",
+                pod != null ? pod.getName() : "unknown");
+    }

Review Comment:
   `describeHostLocation` dereferences `host` unconditionally; if any caller 
passes a null host, this will throw an NPE. Since this is a shared utility in 
`components-api`, it should either (a) explicitly reject null via 
`Objects.requireNonNull(host, ...)` and document it, or (b) provide a safe 
fallback string when `host` is null (e.g., `name: unknown (id: unknown, uuid: 
unknown)`), similar to the existing zone/pod fallbacks.



-- 
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]

Reply via email to