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

rmattingly pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/master by this push:
     new aa89337fc73 HBASE-29186 RegionPlanConditionals can produce a null 
pointer (#6796)
aa89337fc73 is described below

commit aa89337fc7357e58fbc487ecc8f7425e9ef41566
Author: Ray Mattingly <[email protected]>
AuthorDate: Mon Mar 17 13:11:56 2025 -0400

    HBASE-29186 RegionPlanConditionals can produce a null pointer (#6796)
    
    Co-authored-by: Ray Mattingly <[email protected]>
    Signed-off-by: Nick Dimiduk <[email protected]>
---
 .../hbase/master/balancer/RegionPlanConditional.java | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git 
a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java
 
b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java
index 8de371d341c..063f3ba5f72 100644
--- 
a/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java
+++ 
b/hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionPlanConditional.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.hbase.master.balancer;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -85,8 +86,8 @@ public abstract class RegionPlanConditional {
 
     // Check Server
     int[] destinationRegionIndices = 
cluster.regionsPerServer[destinationServerIdx];
-    Set<RegionInfo> serverRegions = 
Arrays.stream(cluster.regionsPerServer[destinationServerIdx])
-      .mapToObj(idx -> cluster.regions[idx]).collect(Collectors.toSet());
+    Set<RegionInfo> serverRegions =
+      getRegionsFromIndex(destinationServerIdx, cluster.regionsPerServer);
     for (int regionIdx : destinationRegionIndices) {
       serverRegions.add(cluster.regions[regionIdx]);
     }
@@ -100,8 +101,7 @@ public abstract class RegionPlanConditional {
 
     // Check Host
     int hostIdx = cluster.serverIndexToHostIndex[destinationServerIdx];
-    Set<RegionInfo> hostRegions = 
Arrays.stream(cluster.regionsPerHost[hostIdx])
-      .mapToObj(idx -> cluster.regions[idx]).collect(Collectors.toSet());
+    Set<RegionInfo> hostRegions = getRegionsFromIndex(hostIdx, 
cluster.regionsPerHost);
     if (isViolatingHost(regionPlan, hostRegions)) {
       return true;
     }
@@ -112,8 +112,7 @@ public abstract class RegionPlanConditional {
 
     // Check Rack
     int rackIdx = cluster.serverIndexToRackIndex[destinationServerIdx];
-    Set<RegionInfo> rackRegions = 
Arrays.stream(cluster.regionsPerRack[rackIdx])
-      .mapToObj(idx -> cluster.regions[idx]).collect(Collectors.toSet());
+    Set<RegionInfo> rackRegions = getRegionsFromIndex(rackIdx, 
cluster.regionsPerRack);
     if (isViolatingRack(regionPlan, rackRegions)) {
       return true;
     }
@@ -130,4 +129,13 @@ public abstract class RegionPlanConditional {
   boolean isViolatingRack(RegionPlan regionPlan, Set<RegionInfo> 
destinationRegions) {
     return false;
   }
+
+  private Set<RegionInfo> getRegionsFromIndex(int index, int[][] 
regionsPerIndex) {
+    int[] regionIndices = regionsPerIndex[index];
+    if (regionIndices == null) {
+      return Collections.emptySet();
+    }
+    return Arrays.stream(regionIndices).mapToObj(idx -> cluster.regions[idx])
+      .collect(Collectors.toSet());
+  }
 }

Reply via email to