Skip to content

Commit dc45fc3

Browse files
adinauerclaude
andcommitted
fix(kafka): Make producer proxy equality reflexive
Return true when the Kafka producer proxy is compared with itself. This preserves existing delegate equality behavior for other comparisons while satisfying the equals contract. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3dba80f commit dc45fc3

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaProducer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ static final class SentryProducerHandler<K, V> implements InvocationHandler {
126126
}
127127
}
128128

129+
if ("equals".equals(method.getName())
130+
&& args != null
131+
&& args.length == 1
132+
&& proxy == args[0]) {
133+
return true;
134+
}
135+
129136
if ("toString".equals(method.getName()) && (args == null || args.length == 0)) {
130137
return "SentryKafkaProducer[delegate=" + delegate + "]";
131138
}

sentry-kafka/src/test/kotlin/io/sentry/kafka/SentryKafkaProducerTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,20 @@ class SentryKafkaProducerTest {
347347
assertNotNull(record.headers().lastHeader(SentryKafkaProducer.SENTRY_ENQUEUED_TIME_HEADER))
348348
}
349349

350+
@Test
351+
fun `wrapped producer equals itself`() {
352+
val producer = SentryKafkaProducer.wrap(delegate, scopes)
353+
354+
assertTrue(producer.equals(producer))
355+
}
356+
357+
@Test
358+
fun `wrapped producer keeps delegate hashCode`() {
359+
val producer = SentryKafkaProducer.wrap(delegate, scopes)
360+
361+
assertEquals(delegate.hashCode(), producer.hashCode())
362+
}
363+
350364
@Test
351365
fun `toString includes delegate`() {
352366
val producer = SentryKafkaProducer.wrap(delegate, scopes)

0 commit comments

Comments
 (0)