From f1dded7d397dbab3cf6088f0654aec93610c8610 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Tue, 23 Sep 2014 10:04:17 +0000
Subject: [PATCH] Fix issue in method ByteStringBuilder#append(DataInput, int) added in r11047

---
 opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java |   12 ++++++++++++
 opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java         |    2 +-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java
index a8e2dbd..ef6d5dc 100755
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java
@@ -494,7 +494,7 @@
 
         ensureAdditionalCapacity(length);
         stream.readFully(buffer, this.length, length);
-        this.length = length;
+        this.length += length;
     }
 
     /**
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java
index 1944b91..cd4db56 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java
@@ -27,6 +27,8 @@
 package org.forgerock.opendj.ldap;
 
 import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.DataInputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
@@ -122,6 +124,15 @@
         Assert.assertEquals(bsb.append(stream, 10), 5);
     }
 
+    @Test
+    public void testAppendDataInputWithNonEmptyBuilder() throws Exception {
+        final ByteStringBuilder bsb = new ByteStringBuilder();
+        bsb.append((byte) 0);
+        final DataInput stream = new DataInputStream(new ByteArrayInputStream(new byte[5]));
+        bsb.append(stream, 5);
+        Assert.assertEquals(bsb.length(), 6);
+    }
+
     @Test(dataProvider = "builderProvider", expectedExceptions = IndexOutOfBoundsException.class)
     public void testClear(final ByteStringBuilder bs, final byte[] ba) {
         bs.clear();
@@ -180,6 +191,7 @@
         Assert.assertTrue(Arrays.equals(trimmedArray, ba));
     }
 
+    @SuppressWarnings("unused")
     @Test(expectedExceptions = IllegalArgumentException.class)
     public void testInvalidCapacity() {
         new ByteStringBuilder(-1);

--
Gitblit v1.10.0