From eb78968ba362e26f4d7919cdfa9451498d00f75f Mon Sep 17 00:00:00 2001 From: Aleksandar Apostolov Date: Fri, 11 Sep 2026 16:57:28 +0200 Subject: [PATCH] fix(test): stop picking a constructor by declaration order getDeclaredConstructors() ordering is unspecified, so .first() started returning the 2-arg private constructor instead of the 3-arg access bridge and newInstance(null, null, null) threw. Reach the both-null state through the external() factory instead and pin the precondition. --- .../StreamCompositeEventSerializationImplTest.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/stream-android-core/src/test/java/io/getstream/android/core/internal/serialization/StreamCompositeEventSerializationImplTest.kt b/stream-android-core/src/test/java/io/getstream/android/core/internal/serialization/StreamCompositeEventSerializationImplTest.kt index 94f040eb..b247075a 100644 --- a/stream-android-core/src/test/java/io/getstream/android/core/internal/serialization/StreamCompositeEventSerializationImplTest.kt +++ b/stream-android-core/src/test/java/io/getstream/android/core/internal/serialization/StreamCompositeEventSerializationImplTest.kt @@ -78,11 +78,18 @@ class StreamCompositeEventSerializationImplTest { @Test fun `serialize - neither core nor product returns failure`() { - // Create an instance with both nulls via reflection (private ctor). - val k = StreamCompositeSerializationEvent::class.java.declaredConstructors.first() - k.isAccessible = true + // `external` takes a nullable T, so a null product reaches the both-null state without + // reflection. The cast is safe — the type parameter is erased and neither field is read + // as a String on this path. @Suppress("UNCHECKED_CAST") - val emptyEvt = k.newInstance(null, null, null) as StreamCompositeSerializationEvent + val emptyEvt = + StreamCompositeSerializationEvent.external(null) + as StreamCompositeSerializationEvent + + // Pin the precondition — if construction stops producing both-null, fail here rather + // than misattributing it to the serializer. + assertNull(emptyEvt.core) + assertNull(emptyEvt.product) val sut = newSut() val res = sut.serialize(emptyEvt)