From 32f2f7771b61edd3e06f92f9b7fff672b1d09dac Mon Sep 17 00:00:00 2001 From: bryanhuhta Date: Tue, 17 Dec 2024 16:37:30 -0700 Subject: [PATCH] Revert the equals() and hashCode() changes --- .../src/main/java/io/pyroscope/labels/Ref.java | 7 ++----- .../src/test/java/io/pyroscope/labels/RefTest.java | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/async-profiler-context/src/main/java/io/pyroscope/labels/Ref.java b/async-profiler-context/src/main/java/io/pyroscope/labels/Ref.java index 0ff901f..8fe85b1 100644 --- a/async-profiler-context/src/main/java/io/pyroscope/labels/Ref.java +++ b/async-profiler-context/src/main/java/io/pyroscope/labels/Ref.java @@ -1,6 +1,5 @@ package io.pyroscope.labels; -import java.util.Objects; import java.util.concurrent.atomic.AtomicLong; class Ref { @@ -19,14 +18,12 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; Ref valueRef = (Ref) o; - if (val.getClass() != o.getClass()) return false; - - return id.equals(valueRef.id) && val.equals(valueRef.val); + return id.equals(valueRef.id); } @Override public int hashCode() { - return Objects.hash(id, val); + return id.hashCode(); } @Override diff --git a/async-profiler-context/src/test/java/io/pyroscope/labels/RefTest.java b/async-profiler-context/src/test/java/io/pyroscope/labels/RefTest.java index bde8747..8fe7d65 100644 --- a/async-profiler-context/src/test/java/io/pyroscope/labels/RefTest.java +++ b/async-profiler-context/src/test/java/io/pyroscope/labels/RefTest.java @@ -22,12 +22,12 @@ void testEquals() { assertTrue(ref1.equals(ref1)); assertFalse(ref1.equals(null)); assertFalse(ref1.equals(new Integer(3))); - assertFalse(ref1.equals(new Ref(3, 1L))); + assertTrue(ref1.equals(new Ref(3, 1L))); // We don't compare the value types. } @Test void testHashCode() { Ref ref1 = new Ref<>("test", 1L); - assertEquals(3557490, ref1.hashCode()); + assertEquals(1, ref1.hashCode()); } }