You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by an...@apache.org on 2016/07/25 15:26:49 UTC

[2/2] activemq-artemis git commit: Fix ByteBuffer regression from Netty upgrade

Fix ByteBuffer regression from Netty upgrade

Using array() is a bit dangerous as it's an optional part of any
ByteBuffer implementation. This new method will deal with various
ByteBuffer implementations appropriately.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/57762053
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/57762053
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/57762053

Branch: refs/heads/master
Commit: 577620533d6a39ba196a69b4464616e1e6b5da5f
Parents: f4e37c3
Author: jbertram <jb...@apache.org>
Authored: Fri Jul 22 11:12:40 2016 -0500
Committer: Andy Taylor <an...@gmail.com>
Committed: Mon Jul 25 16:26:21 2016 +0100

----------------------------------------------------------------------
 .../org/apache/activemq/artemis/utils/ByteUtil.java   | 14 ++++++++++++++
 .../artemis/core/client/impl/ClientConsumerImpl.java  |  3 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/57762053/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
index 50ac3cc..7921072 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.artemis.utils;
 
+import java.nio.ByteBuffer;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
 import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
@@ -90,4 +92,16 @@ public class ByteUtil {
       return sb.toString();
    }
 
+   public static byte[] getActiveArray(ByteBuffer buffer) {
+      byte[] ret = new byte[buffer.remaining()];
+      if (buffer.hasArray()) {
+         byte[] array = buffer.array();
+         System.arraycopy(array, buffer.arrayOffset() + buffer.position(), ret, 0, ret.length);
+      }
+      else {
+         buffer.slice().get(ret);
+      }
+      return ret;
+   }
+
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/57762053/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java
index 57bb869..42168e9 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java
@@ -38,6 +38,7 @@ import org.apache.activemq.artemis.core.client.ActiveMQClientLogger;
 import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle;
 import org.apache.activemq.artemis.spi.core.remoting.ConsumerContext;
 import org.apache.activemq.artemis.spi.core.remoting.SessionContext;
+import org.apache.activemq.artemis.utils.ByteUtil;
 import org.apache.activemq.artemis.utils.FutureLatch;
 import org.apache.activemq.artemis.utils.PriorityLinkedList;
 import org.apache.activemq.artemis.utils.PriorityLinkedListImpl;
@@ -640,7 +641,7 @@ public final class ClientConsumerImpl implements ClientConsumerInternal {
       //sets the packet
       ActiveMQBuffer qbuff = clMessage.getBodyBuffer();
       int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
-      final byte[] body = qbuff.readBytes(bytesToRead).toByteBuffer().array();
+      final byte[] body = ByteUtil.getActiveArray(qbuff.readBytes(bytesToRead).toByteBuffer());
 
       largeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController));
       currentLargeMessageController.addPacket(body, body.length, false);