From 7006ce9dc082d3f3aebb31da00bce0f11c4f24ad Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sat, 8 Aug 2020 14:29:33 -0700 Subject: [PATCH] Added ByteBuf read-only invariant --- core/src/com/riiablo/io/nio/ByteInput.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/com/riiablo/io/nio/ByteInput.java b/core/src/com/riiablo/io/nio/ByteInput.java index a2df0b3a..3e268e4c 100644 --- a/core/src/com/riiablo/io/nio/ByteInput.java +++ b/core/src/com/riiablo/io/nio/ByteInput.java @@ -18,19 +18,20 @@ import com.riiablo.util.DebugUtils; */ // TODO: improve placeholder documentation public class ByteInput { - private static final ByteInput EMPTY_BYTEINPUT = new ByteInput(Unpooled.EMPTY_BUFFER); + private static final ByteInput EMPTY_BYTEINPUT = new ByteInput(Unpooled.EMPTY_BUFFER.asReadOnly()); public static ByteInput emptyByteInput() { return EMPTY_BYTEINPUT; } public static ByteInput wrap(byte[] bytes) { - return bytes == null ? emptyByteInput() : new ByteInput(Unpooled.wrappedBuffer(bytes)); + return bytes == null ? emptyByteInput() : new ByteInput(Unpooled.wrappedBuffer(bytes).asReadOnly()); } private final ByteBuf buffer; private BitInput bitInput; ByteInput(ByteBuf buffer) { + assert buffer.isReadOnly() : "buffer should be tagged ByteBuf#asReadOnly()"; this.buffer = buffer; }