From 625cacb1986eea1fed06457e097bb3cc0032dacd Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Sun, 7 Nov 2021 12:22:11 +0100 Subject: [PATCH] [fix] Fix use of computeIfPresent with HashMap with possible null values Signed-off-by: Emmanuel Bigeon --- .../java/net/bigeon/gclc/command/CommandParameters.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gclc/src/main/java/net/bigeon/gclc/command/CommandParameters.java b/gclc/src/main/java/net/bigeon/gclc/command/CommandParameters.java index 3a83d4f..c768837 100644 --- a/gclc/src/main/java/net/bigeon/gclc/command/CommandParameters.java +++ b/gclc/src/main/java/net/bigeon/gclc/command/CommandParameters.java @@ -207,7 +207,11 @@ public final class CommandParameters { * @param string the key * @param value the value */ public void set(final String string, final String value) { - stringArguments.computeIfPresent(string, - (final String k, final String v) -> value); + // DO NOT USE computeIfPresent. This is a HashMap, not a ConcurrentHashMap and + // keys can be associated to null, but computeIfPresent will consider them as + // absent! + if (stringArguments.containsKey(string)) { + stringArguments.put(string, value); + } } }