diff --git a/core/src/main/java/io/grpc/Attributes.java b/core/src/main/java/io/grpc/Attributes.java index 647a4e42cc1..28e2bd4ae32 100644 --- a/core/src/main/java/io/grpc/Attributes.java +++ b/core/src/main/java/io/grpc/Attributes.java @@ -129,7 +129,18 @@ public boolean equals(Object o) { return false; } Attributes that = (Attributes) o; - return Objects.equal(data, that.data); + if (data.size() != that.data.size()) { + return false; + } + for (Entry, Object> e : data.entrySet()) { + if (!that.data.containsKey(e.getKey())) { + return false; + } + if (!Objects.equal(e.getValue(), that.data.get(e.getKey()))) { + return false; + } + } + return true; } /** diff --git a/core/src/test/java/io/grpc/AttributesTest.java b/core/src/test/java/io/grpc/AttributesTest.java index 329358e5d67..db4e86a324d 100644 --- a/core/src/test/java/io/grpc/AttributesTest.java +++ b/core/src/test/java/io/grpc/AttributesTest.java @@ -17,6 +17,7 @@ package io.grpc; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import org.junit.Test; @@ -50,4 +51,20 @@ public void duplicates() { public void empty() { assertEquals(0, Attributes.EMPTY.keys().size()); } + + @Test + @SuppressWarnings("BoxedPrimitiveConstructor") + public void valueEquality() { + Attributes.Key key = Attributes.Key.of("ints"); + Integer v1 = new Integer(100000); + Integer v2 = new Integer(100000); + + assertNotSame(v1, v2); + assertEquals(v1, v2); + + Attributes attr1 = Attributes.newBuilder().set(key, v1).build(); + Attributes attr2 = Attributes.newBuilder().set(key, v2).build(); + + assertEquals(attr1, attr2); + } }