From 6fdfc9184c8410e38b9d0bb559a8ac89c6fbb2cf Mon Sep 17 00:00:00 2001 From: Peter Lawrey Date: Sun, 30 Nov 2014 14:18:45 +0200 Subject: [PATCH] HCOLL-211 Add BytesMarshaller and improve handling of invalid sizes. --- .../java/net/openhft/chronicle/map/TcpReplicator.java | 3 +-- .../map/fromdocs/StringEncodingExamplesTest.java | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index bc56353bd..2c47b93cc 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -1952,7 +1952,6 @@ class StatelessServerConnector { } private void writeSizeAndFlags(long locationOfSize, boolean isException, Bytes out) { - long currentPosition = out.position(); final long size = out.position() - locationOfSize; out.writeInt(locationOfSize, (int) size); // size out.writeBoolean(locationOfSize + SIZE_OF_SIZE, isException); // isException @@ -1964,7 +1963,7 @@ class StatelessServerConnector { private Map readEntries(Bytes reader) { final long numberOfEntries = reader.readStopBit(); - final HashMap result = new HashMap(); + final Map result = new HashMap(); ThreadLocalCopies copies = keyReaderWithSize.getCopies(null); BytesReader keyReader = keyReaderWithSize.readerForLoop(copies); diff --git a/src/test/java/net/openhft/chronicle/map/fromdocs/StringEncodingExamplesTest.java b/src/test/java/net/openhft/chronicle/map/fromdocs/StringEncodingExamplesTest.java index 86376bd1f..fb2dd851d 100644 --- a/src/test/java/net/openhft/chronicle/map/fromdocs/StringEncodingExamplesTest.java +++ b/src/test/java/net/openhft/chronicle/map/fromdocs/StringEncodingExamplesTest.java @@ -89,11 +89,13 @@ public class StringEncodingExamplesTest { @Override public CharSequence read(Bytes bytes) { - int csLen = (int) bytes.readStopBit(); + long csLen = bytes.readStopBit(); + if (csLen < 0 || csLen > Integer.MAX_VALUE) + throw new IllegalStateException("length invalid: " + csLen); if (returnedCharBuffer == null || returnedCharBuffer.capacity() < csLen) { - returnedCharBuffer = CharBuffer.allocate(csLen); + returnedCharBuffer = CharBuffer.allocate((int) csLen); } else { - returnedCharBuffer.clear().limit(csLen); + returnedCharBuffer.clear().limit((int) csLen); } bytesAsBuffer = bytes.sliceAsByteBuffer(bytesAsBuffer); decoder.decode(bytesAsBuffer, returnedCharBuffer, true);