Remove use of CompositeByteBuf in NettyDataBuffer

Prior to this commit, NettyDataBuffer had a optimization in
write(ByteBuf...), where it used a CompositeByteBuf to hold the original
and the parameter buffer.
Unfortunately, this procedure has nasty consequences when splicing
buffers (see https://stackoverflow.com/a/48111196/839733).

As of this commit, NettyDataBuffer stopped using CompositeByteBuf, and
 simply does ByteBuf.write().

Issue: SPR-16351
This commit is contained in:
Arjen Poutsma
2018-01-10 11:04:42 +01:00
parent 5ed0cf9027
commit e6893da971
2 changed files with 42 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -303,7 +303,7 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
assertArrayEquals(new byte[]{'a', 'b', 'c', 'd'}, result);
release(buffer1);
release(buffer1, buffer2, buffer3);
}
@Test
@@ -461,5 +461,23 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
release(buffer);
}
@Test
public void spr16351() {
DataBuffer buffer = createDataBuffer(6);
byte[] bytes = {'a', 'b', 'c', 'd', 'e', 'f'};
buffer.write(bytes);
DataBuffer slice = buffer.slice(3, 3);
buffer.writePosition(3);
buffer.write(slice);
assertEquals(6, buffer.readableByteCount());
byte[] result = new byte[6];
buffer.read(result);
assertArrayEquals(bytes, result);
release(buffer);
}
}