From c87ba0e2192e0ca1627dd6d9c3791c546f6bfe88 Mon Sep 17 00:00:00 2001 From: waterWang Date: Tue, 28 Jul 2026 17:14:28 +0800 Subject: [PATCH] Fix NPE in canCompleteSwap when path doesn't exist When baseAccessor.getChildNames() returns null because the current state path doesn't exist, iterating over the result causes a NullPointerException. Added a null check that returns true when no current states are found, indicating the swap is complete. Fixes #3069 --- .../main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java index 5d917587e8..cec70978fd 100644 --- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java +++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java @@ -552,6 +552,10 @@ private boolean canCompleteSwap(String clusterName, String swapOutInstanceName, List swapOutResources = baseAccessor.getChildNames( PropertyPathBuilder.instanceCurrentState(clusterName, swapOutInstanceName, swapOutLastActiveSession), 0); + if (swapOutResources == null) { + // No current states found for the swap-out instance, swap is complete + return true; + } for (String swapOutResource : swapOutResources) { // Get the topState and secondTopStates for the stateModelDef used by the resource. IdealState idealState = accessor.getProperty(keyBuilder.idealStates(swapOutResource));