Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2015-12-18 10:20:30 +0000
committerEike Stepper2015-12-18 10:20:30 +0000
commitb66cb8c692f7d0bde4a629a2b06fd98427e63a3a (patch)
treeaa3885093fd9ce2c57f3a8e3599e5059ebb645e6
parent35dfd3f3110824a47bb7f692705a7055699e94f6 (diff)
downloadcdo-b66cb8c692f7d0bde4a629a2b06fd98427e63a3a.tar.gz
cdo-b66cb8c692f7d0bde4a629a2b06fd98427e63a3a.tar.xz
cdo-b66cb8c692f7d0bde4a629a2b06fd98427e63a3a.zip
[484649] IllegalArgumentException in Buffer.limit()
https://bugs.eclipse.org/bugs/show_bug.cgi?id=484649
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java37
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java23
2 files changed, 55 insertions, 5 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
index 18980d3bad..340f9ff1bf 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
@@ -11,7 +11,9 @@
*/
package org.eclipse.net4j.tests;
+import org.eclipse.net4j.ITransportConfigAware;
import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.tests.data.HugeData;
import org.eclipse.net4j.tests.data.TinyData;
import org.eclipse.net4j.tests.signal.ArrayRequest;
import org.eclipse.net4j.tests.signal.TestSignalProtocol;
@@ -46,6 +48,33 @@ public abstract class ChannelTest extends AbstractProtocolTest
{
}
+ public void testAllBufferSizes() throws Exception
+ {
+ disableConsole();
+
+ TestSignalProtocol protocol = openTestSignalProtocol();
+ assertActive(protocol);
+
+ byte[] data = HugeData.getBytes();
+ assertEquals(true,
+ data.length > 2 * ((ITransportConfigAware)getConnector()).getConfig().getBufferProvider().getBufferCapacity());
+
+ for (int i = 1; i < data.length; i++)
+ {
+ // System.out.println(i);
+
+ byte[] dataToSend = new byte[i];
+ System.arraycopy(data, 0, dataToSend, 0, i);
+
+ byte[] result = new ArrayRequest(protocol, dataToSend).send();
+ assertEquals(true, Arrays.equals(dataToSend, result));
+ }
+
+ protocol.close();
+ assertInactive(protocol);
+ enableConsole();
+ }
+
public void testSingleThreadNoData() throws Exception
{
final LatchTimeOuter timeOuter = new LatchTimeOuter(4);
@@ -318,12 +347,12 @@ public abstract class ChannelTest extends AbstractProtocolTest
/**
* @author Eike Stepper
*/
- public static final class TCP extends ChannelTest
+ public static final class JVM extends ChannelTest
{
@Override
protected boolean useJVMTransport()
{
- return false;
+ return true;
}
@Override
@@ -336,12 +365,12 @@ public abstract class ChannelTest extends AbstractProtocolTest
/**
* @author Eike Stepper
*/
- public static final class JVM extends ChannelTest
+ public static final class TCP extends ChannelTest
{
@Override
protected boolean useJVMTransport()
{
- return true;
+ return false;
}
@Override
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
index ea3db22235..065c5dd1ba 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
@@ -214,7 +214,28 @@ public class Buffer implements InternalBuffer
payloadSize -= FLAGS_OFFSET;
byteBuffer.clear();
- byteBuffer.limit(payloadSize);
+
+ try
+ {
+ byteBuffer.limit(payloadSize);
+ }
+ catch (IllegalArgumentException ex)
+ {
+ if (payloadSize < 0)
+ {
+ throw new IllegalArgumentException("New limit " + payloadSize + " is < 0" + (isEOS() ? " (EOS)" : ""), ex);
+ }
+
+ int capacity = byteBuffer.capacity();
+ if (payloadSize > capacity)
+ {
+ throw new IllegalArgumentException(
+ "New limit " + payloadSize + " is > " + capacity + (isEOS() ? " (EOS)" : ""), ex);
+ }
+
+ throw ex;
+ }
+
state = BufferState.READING_BODY;
}

Back to the top