From 24a315ef699c5de4c2015e30bae2de103ab7d2de Mon Sep 17 00:00:00 2001 From: Seoyoung Park Date: Wed, 6 Sep 2023 11:59:16 +0900 Subject: [PATCH] [#noissue] Backport: Add NPE Check in Hbase plugin --- .../hbase/interceptor/data/DataSizeUtils.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/data/DataSizeUtils.java b/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/data/DataSizeUtils.java index 5acbceefbfcd..48830858b3b8 100644 --- a/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/data/DataSizeUtils.java +++ b/plugins/hbase/src/main/java/com/navercorp/pinpoint/plugin/hbase/interceptor/data/DataSizeUtils.java @@ -1,9 +1,11 @@ package com.navercorp.pinpoint.plugin.hbase.interceptor.data; +import com.navercorp.pinpoint.common.util.ArrayUtils; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.client.Mutation; import org.apache.hadoop.hbase.client.Result; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.NavigableMap; @@ -24,11 +26,11 @@ private DataSizeUtils() { } public static int sizeOfMutation(Mutation mutation) { - return mutation.getRow().length + sumOfFamilyCellMap(mutation.getFamilyCellMap()); + return ArrayUtils.getLength(mutation.getRow()) + sumOfFamilyCellMap(mutation.getFamilyCellMap()); } public static int sizeOfResult(Result result) { - return result.getRow().length + sumOfResultFamilyMap(result.getNoVersionMap()); + return ArrayUtils.getLength(result.getRow()) + sumOfResultFamilyMap(result.getNoVersionMap()); } public static int sumOfFamilyCellMap(NavigableMap> map) { @@ -37,7 +39,7 @@ public static int sumOfFamilyCellMap(NavigableMap> map) { } int sizeInByte = 0; for (Map.Entry> e : map.entrySet()) { - sizeInByte += e.getKey().length; + sizeInByte += ArrayUtils.getLength(e.getKey()); for (Cell cell : e.getValue()) { sizeInByte += lengthOfCell(cell); } @@ -48,10 +50,10 @@ public static int sumOfFamilyCellMap(NavigableMap> map) { public static int sumOfResultFamilyMap(NavigableMap> map) { int sizeInByte = 0; for (Map.Entry> familyToRest : map.entrySet()) { - sizeInByte += familyToRest.getKey().length; + sizeInByte += ArrayUtils.getLength(familyToRest.getKey()); for (Map.Entry qualifierToValue : familyToRest.getValue().entrySet()) { - sizeInByte += qualifierToValue.getKey().length; - sizeInByte += qualifierToValue.getValue().length; + sizeInByte += ArrayUtils.getLength(qualifierToValue.getKey()); + sizeInByte += ArrayUtils.getLength(qualifierToValue.getValue()); } } return sizeInByte;