From 544e47c9e74d48b201512d9804f12bc082d0de9b Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Thu, 24 Sep 2015 16:43:29 -0700 Subject: [PATCH] Don't release buffer after single use. --- .../java/org/spacehq/mc/protocol/ByteBufHelper.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/spacehq/mc/protocol/ByteBufHelper.java b/src/test/java/org/spacehq/mc/protocol/ByteBufHelper.java index 092caf3a..8a063490 100644 --- a/src/test/java/org/spacehq/mc/protocol/ByteBufHelper.java +++ b/src/test/java/org/spacehq/mc/protocol/ByteBufHelper.java @@ -21,12 +21,10 @@ public class ByteBufHelper { public static final ByteBufNetInput in = new ByteBufNetInput(buffer); @SuppressWarnings("unchecked") - public static T writeAndRead(Packet writable){ - if(buffer.isReadable()) { - buffer.release(); - } - + public static T writeAndRead(Packet writable) { try { + buffer.clear(); + writable.write(out); // Creating new fresh packet to reset fields. @@ -41,8 +39,6 @@ public class ByteBufHelper { return (T) readable; } catch(Exception e) { throw new IllegalStateException("Failed parse packet", e); - } finally { - buffer.release(); } }