PROTON-1941: throw BOE in the BB wrapper, preserve historic encoding behaviour for compatibility
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java b/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java
index 034a23e..1dcae28 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec/WritableBuffer.java
@@ -145,9 +145,11 @@
             }
 
             if (_buf.remaining() < remaining) {
-                throw new IndexOutOfBoundsException(String.format(
+                IndexOutOfBoundsException cause = new IndexOutOfBoundsException(String.format(
                     "Requested min remaining bytes(%d) exceeds remaining(%d) in underlying ByteBuffer: %s",
                     remaining, _buf.remaining(), _buf));
+
+                throw (BufferOverflowException) new BufferOverflowException().initCause(cause);
             }
         }
 
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/WritableBufferTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/WritableBufferTest.java
index b3900bb..7509cf6 100644
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/WritableBufferTest.java
+++ b/proton-j/src/test/java/org/apache/qpid/proton/codec/WritableBufferTest.java
@@ -21,6 +21,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
 
 import org.junit.Test;
@@ -80,7 +81,7 @@
     }
 
     @Test
-    public void testEnsureReminingThrowsWhenExpected() {
+    public void testEnsureRemainingThrowsWhenExpected() {
         ByteBuffer data = ByteBuffer.allocate(100);
         WritableBuffer buffer = WritableBuffer.ByteBufferWrapper.wrap(data);
 
@@ -88,7 +89,7 @@
         try {
             buffer.ensureRemaining(1024);
             fail("Should have thrown an error on request for more than is available.");
-        } catch (IndexOutOfBoundsException iobe) {}
+        } catch (BufferOverflowException boe) {}
 
         try {
             buffer.ensureRemaining(-1);
@@ -97,7 +98,7 @@
     }
 
     @Test
-    public void testEnsureReminingDefaultImplementation() {
+    public void testEnsureRemainingDefaultImplementation() {
         WritableBuffer buffer = new DefaultWritableBuffer();
 
         try {