This is an automated email from the ASF dual-hosted git repository.
sureshanaparti pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.20 by this push:
new b93f603d315 api: fix inverted value comparison in
ImageStoreDetailResponse.equals (#14023)
b93f603d315 is described below
commit b93f603d315ceeadf3bba375e1f28bb3a3695a6c
Author: Ramgopal Nagaboina <[email protected]>
AuthorDate: Thu Sep 10 03:11:28 2026 -0400
api: fix inverted value comparison in ImageStoreDetailResponse.equals
(#14023)
equals() returned false when the two responses had the SAME value and true
when the values DIFFERED (the value branch was inverted):
else if (this.getValue().equals(other.getValue()))
return false;
So two identical details were treated as unequal and two details differing
only by value were treated as equal, corrupting any Set/Map/dedup keyed on
ImageStoreDetailResponse. It also NPEd when value was null.
Compare with !Objects.equals(getValue(), other.getValue()), which restores
the correct result and is null-safe.
Adds tests for equal name+value, differing value, and differing name.
---
.../api/response/ImageStoreDetailResponse.java | 4 +-
.../api/response/ImageStoreDetailResponseTest.java | 45 ++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git
a/api/src/main/java/org/apache/cloudstack/api/response/ImageStoreDetailResponse.java
b/api/src/main/java/org/apache/cloudstack/api/response/ImageStoreDetailResponse.java
index 0afef6166f8..036f5f0d170 100644
---
a/api/src/main/java/org/apache/cloudstack/api/response/ImageStoreDetailResponse.java
+++
b/api/src/main/java/org/apache/cloudstack/api/response/ImageStoreDetailResponse.java
@@ -16,6 +16,8 @@
// under the License.
package org.apache.cloudstack.api.response;
+import java.util.Objects;
+
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;
@@ -81,7 +83,7 @@ public class ImageStoreDetailResponse extends BaseResponse {
return false;
} else if (!oid.equals(other.getName()))
return false;
- else if (this.getValue().equals(other.getValue()))
+ else if (!Objects.equals(this.getValue(), other.getValue()))
return false;
return true;
}
diff --git
a/api/src/test/java/org/apache/cloudstack/api/response/ImageStoreDetailResponseTest.java
b/api/src/test/java/org/apache/cloudstack/api/response/ImageStoreDetailResponseTest.java
new file mode 100644
index 00000000000..8550eac9fc1
--- /dev/null
+++
b/api/src/test/java/org/apache/cloudstack/api/response/ImageStoreDetailResponseTest.java
@@ -0,0 +1,45 @@
+// 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 org.apache.cloudstack.api.response;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ImageStoreDetailResponseTest {
+
+ @Test
+ public void equalsIsTrueForSameNameAndValue() {
+ ImageStoreDetailResponse a = new ImageStoreDetailResponse("key",
"value");
+ ImageStoreDetailResponse b = new ImageStoreDetailResponse("key",
"value");
+ Assert.assertEquals(a, b);
+ Assert.assertEquals(a.hashCode(), b.hashCode());
+ }
+
+ @Test
+ public void equalsIsFalseWhenValueDiffers() {
+ ImageStoreDetailResponse a = new ImageStoreDetailResponse("key",
"value");
+ ImageStoreDetailResponse c = new ImageStoreDetailResponse("key",
"other");
+ Assert.assertNotEquals(a, c);
+ }
+
+ @Test
+ public void equalsIsFalseWhenNameDiffers() {
+ ImageStoreDetailResponse a = new ImageStoreDetailResponse("key",
"value");
+ ImageStoreDetailResponse d = new ImageStoreDetailResponse("other",
"value");
+ Assert.assertNotEquals(a, d);
+ }
+}