You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/01/07 15:52:21 UTC

[plc4x] branch next-gen-core updated: PLC4X-163 - Netty OutOfDirectMemoryError - Fixed two bugs in the detection if more bytes are available and in the way the number of elements in primitive arrays are detected.

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

cdutz pushed a commit to branch next-gen-core
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/next-gen-core by this push:
     new 94bba6c  PLC4X-163 - Netty OutOfDirectMemoryError - Fixed two bugs in the detection if more bytes are available and in the way the number of elements in primitive arrays are detected.
94bba6c is described below

commit 94bba6cf8d787d62eacc29907cbdad1e896c5e29
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Jan 7 16:52:14 2020 +0100

    PLC4X-163 - Netty OutOfDirectMemoryError
    - Fixed two bugs in the detection if more bytes are available and in the way the number of elements in primitive arrays are detected.
---
 .../plc4x/java/spi/generation/ReadBuffer.java      |  2 +-
 .../plc4x/java/spi/generation/StaticHelper.java    | 35 ++++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java
index 943c646..90eff15 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java
@@ -48,7 +48,7 @@ public class ReadBuffer {
     }
 
     public boolean hasMore(int numBits) {
-        return (numBits / 8) > (totalBytes - getPos());
+        return (numBits / 8) < (totalBytes - getPos());
     }
 
     public byte peekByte(int offset) throws ParseException {
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
index ba4bc6f..21b8e12 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java
@@ -24,8 +24,39 @@ public class StaticHelper {
 
     public static int COUNT(Object obj) {
         if (obj.getClass().isArray()) {
-            Object[] arr = (Object[]) obj;
-            return arr.length;
+            if(obj.getClass().getComponentType() != null && obj.getClass().getComponentType().isPrimitive()) {
+                if(obj.getClass().getComponentType() == boolean.class) {
+                    boolean[] arr = (boolean[]) obj;
+                    return arr.length;
+                }
+                if(obj.getClass().getComponentType() == byte.class) {
+                    byte[] arr = (byte []) obj;
+                    return arr.length;
+                }
+                if(obj.getClass().getComponentType() == short.class) {
+                    short[] arr = (short []) obj;
+                    return arr.length;
+                }
+                if(obj.getClass().getComponentType() == int.class) {
+                    int[] arr = (int []) obj;
+                    return arr.length;
+                }
+                if(obj.getClass().getComponentType() == long.class) {
+                    long[] arr = (long []) obj;
+                    return arr.length;
+                }
+                if(obj.getClass().getComponentType() == float.class) {
+                    float[] arr = (float []) obj;
+                    return arr.length;
+                }
+                if(obj.getClass().getComponentType() == double.class) {
+                    double[] arr = (double[]) obj;
+                    return arr.length;
+                }
+            } else {
+                Object[] arr = (Object[]) obj;
+                return arr.length;
+            }
         } else if (obj instanceof Collection) {
             Collection col = (Collection) obj;
             return col.size();