From bd3a2ebb0e036da454f7f58af7ef03d933f77990 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Mon, 11 Dec 2017 14:21:14 -0800 Subject: [PATCH 1/3] core: fix Attributes value equality Fixes: #3857 --- core/src/main/java/io/grpc/Attributes.java | 13 ++++++++++++- core/src/test/java/io/grpc/AttributesTest.java | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) 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..a2912a6c373 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,19 @@ public void duplicates() { public void empty() { assertEquals(0, Attributes.EMPTY.keys().size()); } + + @Test + public void valueEquality() { + Attributes.Key INT_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(INT_KEY, v1).build(); + Attributes attr2 = Attributes.newBuilder().set(INT_KEY, v2).build(); + + assertEquals(attr1, attr2); + } } From 435a2faa41e150f47bfe09821c9cad658c886be3 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Mon, 11 Dec 2017 17:47:27 -0800 Subject: [PATCH 2/3] lay down a suppression field --- core/src/test/java/io/grpc/AttributesTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/io/grpc/AttributesTest.java b/core/src/test/java/io/grpc/AttributesTest.java index a2912a6c373..787e5f64f39 100644 --- a/core/src/test/java/io/grpc/AttributesTest.java +++ b/core/src/test/java/io/grpc/AttributesTest.java @@ -53,6 +53,7 @@ public void empty() { } @Test + @SuppressWarnings("BoxedPrimitiveConstructor") public void valueEquality() { Attributes.Key INT_KEY = Attributes.Key.of("ints"); Integer v1 = new Integer(100000); From 6a41f3286a9980f99e67cd46711f2223bffe6c67 Mon Sep 17 00:00:00 2001 From: Carl Mastrangelo Date: Mon, 11 Dec 2017 17:54:54 -0800 Subject: [PATCH 3/3] remove some pocket lint --- core/src/test/java/io/grpc/AttributesTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/io/grpc/AttributesTest.java b/core/src/test/java/io/grpc/AttributesTest.java index 787e5f64f39..db4e86a324d 100644 --- a/core/src/test/java/io/grpc/AttributesTest.java +++ b/core/src/test/java/io/grpc/AttributesTest.java @@ -55,15 +55,15 @@ public void empty() { @Test @SuppressWarnings("BoxedPrimitiveConstructor") public void valueEquality() { - Attributes.Key INT_KEY = Attributes.Key.of("ints"); + 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(INT_KEY, v1).build(); - Attributes attr2 = Attributes.newBuilder().set(INT_KEY, v2).build(); + Attributes attr1 = Attributes.newBuilder().set(key, v1).build(); + Attributes attr2 = Attributes.newBuilder().set(key, v2).build(); assertEquals(attr1, attr2); }