You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2016/01/20 20:44:20 UTC

[5/5] accumulo git commit: ACCUMULO-4113 Fix ByteBuffer misuse thats occurs in 1.8 and not in 1.7

ACCUMULO-4113 Fix ByteBuffer misuse thats occurs in 1.8 and not in 1.7


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/739f906c
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/739f906c
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/739f906c

Branch: refs/heads/master
Commit: 739f906cfba9ca300f615f820f588de3f195cff9
Parents: 90a4c61
Author: Keith Turner <kt...@apache.org>
Authored: Wed Jan 20 14:40:43 2016 -0500
Committer: Keith Turner <kt...@apache.org>
Committed: Wed Jan 20 14:40:43 2016 -0500

----------------------------------------------------------------------
 .../org/apache/accumulo/core/util/ByteBufferUtil.java     |  8 ++++++++
 .../org/apache/accumulo/core/util/ByteBufferUtilTest.java | 10 ++++++++++
 .../replication/BatchWriterReplicationReplayer.java       |  4 ++--
 .../org/apache/accumulo/test/proxy/SimpleProxyBase.java   |  8 ++++----
 4 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/739f906c/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
index 85c3e12..006755f 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/ByteBufferUtil.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.core.util;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
+import java.io.ByteArrayInputStream;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -102,6 +103,13 @@ public class ByteBufferUtil {
     } else {
       out.write(toBytes(buffer));
     }
+  }
 
+  public static ByteArrayInputStream toByteArrayInputStream(ByteBuffer buffer){
+    if (buffer.hasArray()) {
+      return new ByteArrayInputStream(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
+    } else {
+      return new ByteArrayInputStream(toBytes(buffer));
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/739f906c/core/src/test/java/org/apache/accumulo/core/util/ByteBufferUtilTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/ByteBufferUtilTest.java b/core/src/test/java/org/apache/accumulo/core/util/ByteBufferUtilTest.java
index f27a1ba..d6e1b35 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/ByteBufferUtilTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/ByteBufferUtilTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.accumulo.core.util;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -54,6 +55,15 @@ public class ByteBufferUtilTest {
     }
 
     Assert.assertEquals(expected, new String(baos.toByteArray(), Charsets.UTF_8));
+
+    ByteArrayInputStream bais = ByteBufferUtil.toByteArrayInputStream(bb);
+    byte[] buffer = new byte[expected.length()];
+    try {
+      bais.read(buffer);
+      Assert.assertEquals(expected, new String(buffer, Charsets.UTF_8));
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/accumulo/blob/739f906c/server/tserver/src/main/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayer.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayer.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayer.java
index 8a80ea3..e5e9e80 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayer.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/replication/BatchWriterReplicationReplayer.java
@@ -16,7 +16,6 @@
  */
 package org.apache.accumulo.tserver.replication;
 
-import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -40,6 +39,7 @@ import org.apache.accumulo.core.replication.thrift.RemoteReplicationErrorCode;
 import org.apache.accumulo.core.replication.thrift.RemoteReplicationException;
 import org.apache.accumulo.core.replication.thrift.WalEdits;
 import org.apache.accumulo.core.security.ColumnVisibility;
+import org.apache.accumulo.core.util.ByteBufferUtil;
 import org.apache.accumulo.server.data.ServerMutation;
 import org.apache.accumulo.tserver.logger.LogFileKey;
 import org.apache.accumulo.tserver.logger.LogFileValue;
@@ -64,7 +64,7 @@ public class BatchWriterReplicationReplayer implements AccumuloReplicationReplay
     long mutationsApplied = 0l;
     try {
       for (ByteBuffer edit : data.getEdits()) {
-        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(edit.array()));
+        DataInputStream dis = new DataInputStream(ByteBufferUtil.toByteArrayInputStream(edit));
         try {
           key.readFields(dis);
           // TODO this is brittle because AccumuloReplicaSystem isn't actually calling LogFileValue.write, but we're expecting

http://git-wip-us.apache.org/repos/asf/accumulo/blob/739f906c/test/src/main/java/org/apache/accumulo/test/proxy/SimpleProxyBase.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/proxy/SimpleProxyBase.java b/test/src/main/java/org/apache/accumulo/test/proxy/SimpleProxyBase.java
index 8c6811f..5c892ef 100644
--- a/test/src/main/java/org/apache/accumulo/test/proxy/SimpleProxyBase.java
+++ b/test/src/main/java/org/apache/accumulo/test/proxy/SimpleProxyBase.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.test.proxy;
 
+import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
 import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -126,7 +127,6 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Iterators;
 import com.google.common.net.HostAndPort;
-import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
 
 /**
  * Call every method on the proxy and try to verify that it works.
@@ -1188,7 +1188,7 @@ public abstract class SimpleProxyBase extends SharedMiniClusterBase {
     if (!isKerberosEnabled()) {
       password = s2bb("");
       client.changeLocalUserPassword(creds, user, password);
-      assertTrue(client.authenticateUser(creds, user, s2pp(new String(password.array(), password.position(), password.limit(), UTF_8))));
+      assertTrue(client.authenticateUser(creds, user, s2pp(ByteBufferUtil.toString(password))));
     }
 
     if (isKerberosEnabled()) {
@@ -1207,7 +1207,7 @@ public abstract class SimpleProxyBase extends SharedMiniClusterBase {
       }
     } else {
       // check login with new password
-      client.login(user, s2pp(new String(password.array(), password.position(), password.limit(), UTF_8)));
+      client.login(user, s2pp(ByteBufferUtil.toString(password)));
     }
   }
 
@@ -1242,7 +1242,7 @@ public abstract class SimpleProxyBase extends SharedMiniClusterBase {
       userName = getUniqueNames(1)[0];
       // create a user
       client.createLocalUser(creds, userName, password);
-      user = client.login(userName, s2pp(new String(password.array(), password.position(), password.limit(), UTF_8)));
+      user = client.login(userName, s2pp(ByteBufferUtil.toString(password)));
     }
 
     // check permission failure