From 75b54e630205acd1f2e3f47324b56b945c815d66 Mon Sep 17 00:00:00 2001 From: themode Date: Sat, 1 Jan 2022 20:52:01 +0100 Subject: [PATCH] Ensure proper buffer caching --- src/test/java/network/SendablePacketTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/network/SendablePacketTest.java b/src/test/java/network/SendablePacketTest.java index 78ec0ffcb..f481ebcdc 100644 --- a/src/test/java/network/SendablePacketTest.java +++ b/src/test/java/network/SendablePacketTest.java @@ -35,8 +35,11 @@ public class SendablePacketTest { assertSame(packet, cached.packet()); var buffer = PacketUtils.allocateTrimmedPacket(packet); - assertEquals(buffer.body(), cached.body()); - assertEquals(buffer.body(), cached.body()); + var cachedBuffer = cached.body(); + assertEquals(buffer.body(), cachedBuffer); + // May fail in the very unlikely case where soft references are cleared + // Rare enough to make this test worth it + assertSame(cached.body(), cachedBuffer); assertSame(packet, cached.packet()); }