From 7a626cd6ba23c5c569770c724bd5a418693b1dbe Mon Sep 17 00:00:00 2001 From: Lea Morschel Date: Mon, 28 Nov 2022 12:44:44 +0100 Subject: [PATCH] dcache-chimera: prevent PoolInformationBase NPE Motivation: A NPE was reported in the PoolInformationBase#remove method. Modification: Check if the list of hsms for a pool is null, which is since recently also the case for pools that are are configured as `lfs=precious`. Result: Don't throw a NullPointerException when the associated hsms for a pool are stored as `null`. Target: master Request: 8.2 Request: 8.1 Request: 8.0 Request: 7.2 Fixes: #6879 Requires-notes: yes Requires-book: no Patch: https://rb.dcache.org/r/13797/ Acked-by: Tigran Mkrtchyan --- .../namespace/PoolInformationBase.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java index ddc63e2627e..b2ff735d395 100644 --- a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java +++ b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/PoolInformationBase.java @@ -74,13 +74,18 @@ public synchronized PoolInformation getPoolWithHSM(String hsm) { */ public synchronized void remove(String name) { PoolInformation pool = _pools.remove(name); - if (pool != null) { - for (String hsm : pool.getHsmInstances()) { - Collection pools = _hsmToPool.get(hsm); - pools.remove(pool); - if (pools.isEmpty()) { - _hsmToPool.remove(hsm); - } + if (pool == null) { + return; + } + Collection hsms = pool.getHsmInstances(); + if (hsms == null) { + return; + } + for (String hsm : hsms) { + Collection pools = _hsmToPool.get(hsm); + pools.remove(pool); + if (pools.isEmpty()) { + _hsmToPool.remove(hsm); } } }