From 9b39e7e6fe251abdf2f8138894c9df6627add342 Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Wed, 27 May 2026 13:19:44 +0300 Subject: [PATCH] Fix WMI_WRONG_MAP_ITERATOR in JSONParser and make SpotBugs fail CI JSONParser.writeJsonValue iterated the Map via keySet() and re-resolved each value with m.get(key), tripping SpotBugs' WMI_WRONG_MAP_ITERATOR (performance). Switched to entrySet() iteration so the hash lookup is done once per entry; the null-drop semantics and surrounding comment are preserved. The SpotBugs execution in maven/core-unittests was only bound to the `spotbugs` goal, which generates the XML report but does not break the build on findings regardless of `failOnError`. Added the `check` goal to the same execution so any reported bug (>= Low priority, per the existing threshold) aborts CI. The `spotbugs` goal stays bound so the quality-artifact pipeline still receives the XML report on success. Co-Authored-By: Claude Opus 4.7 (1M context) --- CodenameOne/src/com/codename1/io/JSONParser.java | 7 ++++--- maven/core-unittests/pom.xml | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CodenameOne/src/com/codename1/io/JSONParser.java b/CodenameOne/src/com/codename1/io/JSONParser.java index da887f03d9..2b8ea320df 100644 --- a/CodenameOne/src/com/codename1/io/JSONParser.java +++ b/CodenameOne/src/com/codename1/io/JSONParser.java @@ -849,8 +849,9 @@ private static void writeJsonValue(StringBuilder sb, Object o) { sb.append('{'); boolean first = true; Map m = (Map) o; - for (Object kObj : m.keySet()) { - Object v = m.get(kObj); + for (Object entryObj : m.entrySet()) { + Map.Entry entry = (Map.Entry) entryObj; + Object v = entry.getValue(); if (v == null) { // Null-valued entries are dropped on purpose; if // a caller really needs `"k":null` on the wire, @@ -861,7 +862,7 @@ private static void writeJsonValue(StringBuilder sb, Object o) { sb.append(','); } first = false; - writeJsonString(sb, kObj.toString()); + writeJsonString(sb, entry.getKey().toString()); sb.append(':'); writeJsonValue(sb, v); } diff --git a/maven/core-unittests/pom.xml b/maven/core-unittests/pom.xml index bbb18ba937..584ed4d1e2 100644 --- a/maven/core-unittests/pom.xml +++ b/maven/core-unittests/pom.xml @@ -84,7 +84,17 @@ spotbugs verify + spotbugs + check