This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit c72b226bfb74a4a3895f6d19d41da3486c53fccb
Author: Francesco Nigro <[email protected]>
AuthorDate: Fri May 29 18:17:11 2020 +0200

    ARTEMIS-2785 io.netty.util.internal.OutOfDirectMemoryError during uncompress
---
 .../main/java/org/apache/activemq/artemis/utils/ByteUtil.java | 11 -----------
 .../activemq/artemis/core/client/impl/ClientConsumerImpl.java |  7 +++----
 .../activemq/artemis/core/message/impl/CoreMessage.java       |  7 ++++---
 3 files changed, 7 insertions(+), 18 deletions(-)

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 59f5ce1..84264d3 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
@@ -239,17 +239,6 @@ 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;
-   }
-
    public static long convertTextBytes(final String text) {
       try {
          Matcher m = ONE.matcher(text);
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 7f9ede3..83ee890 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
@@ -39,7 +39,6 @@ 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.ReusableLatch;
 import org.apache.activemq.artemis.utils.TokenBucketLimiter;
@@ -655,9 +654,9 @@ public final class ClientConsumerImpl implements 
ClientConsumerInternal {
 
       //sets the packet
       ActiveMQBuffer qbuff = clMessage.toCore().getBodyBuffer();
-      int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
-      final byte[] body = 
ByteUtil.getActiveArray(qbuff.readBytes(bytesToRead).toByteBuffer());
-
+      final int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
+      final byte[] body = new byte[bytesToRead];
+      qbuff.readBytes(body);
       largeMessage.setLargeMessageController(new 
CompressedLargeMessageControllerImpl(currentLargeMessageController));
       currentLargeMessageController.addPacket(body, body.length, false);
 
diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
index 86ca28a..7ad2c6b 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java
@@ -44,7 +44,6 @@ import 
org.apache.activemq.artemis.core.persistence.CoreMessageObjectPools;
 import org.apache.activemq.artemis.core.persistence.Persister;
 import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
 import org.apache.activemq.artemis.reader.MessageUtil;
-import org.apache.activemq.artemis.utils.ByteUtil;
 import org.apache.activemq.artemis.utils.DataConstants;
 import org.apache.activemq.artemis.utils.UUID;
 import org.apache.activemq.artemis.utils.collections.TypedProperties;
@@ -251,9 +250,11 @@ public class CoreMessage extends RefCountMessage 
implements ICoreMessage {
    }
 
    private ActiveMQBuffer inflate(ActiveMQBuffer buffer) throws 
DataFormatException {
-      int bytesToRead = buffer.readableBytes();
+      final int bytesToRead = buffer.readableBytes();
       Inflater inflater = new Inflater();
-      
inflater.setInput(ByteUtil.getActiveArray(buffer.readBytes(bytesToRead).toByteBuffer()));
+      final byte[] input = new byte[bytesToRead];
+      buffer.readBytes(input);
+      inflater.setInput(input);
 
       //get the real size of large message
       long sizeBody = getLongProperty(Message.HDR_LARGE_BODY_SIZE);

Reply via email to