Subject: [PATCH] #22898
---
Index: src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java b/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
--- a/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java	(revision 18711)
+++ b/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java	(date 1682364669603)
@@ -430,8 +430,7 @@
             final IPreferences pref = Config.getPref();
             if (pref instanceof MemoryPreferences) {
                 final MemoryPreferences memoryPreferences = (MemoryPreferences) pref;
-                tempPreferences.getAllSettings().entrySet().stream().filter(entry -> entry.getValue().isNew())
-                        .forEach(entry -> memoryPreferences.putSetting(entry.getKey(), entry.getValue()));
+                tempPreferences.getAllSettings().forEach(memoryPreferences::putSetting);
             } else {
                 throw new JosmRuntimeException(tr("Preferences are not the expected type"));
             }
Index: test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java b/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java
--- a/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java	(revision 18711)
+++ b/test/unit/org/openstreetmap/josm/data/validation/ValidatorCLITest.java	(date 1682367355980)
@@ -9,6 +9,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.lang.reflect.InvocationTargetException;
 import java.nio.charset.StandardCharsets;
@@ -45,6 +46,7 @@
 import org.openstreetmap.josm.io.OsmWriter;
 import org.openstreetmap.josm.io.OsmWriterFactory;
 import org.openstreetmap.josm.spi.lifecycle.Lifecycle;
+import org.openstreetmap.josm.spi.preferences.Config;
 import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
 import org.openstreetmap.josm.tools.Logging;
 import org.openstreetmap.josm.tools.Utils;
@@ -175,6 +177,28 @@
         Files.deleteIfExists(Paths.get(errorPath));
     }
 
+    /**
+     * A non-regression test for #22898: Validator CLI errors out when is run with --load-preferences argument
+     */
+    @Test
+    void testNonRegression22898(final @TempDir Path preferencesLocation) throws IOException {
+        final ValidatorCLI validatorCLI = new ValidatorCLI();
+        final Path preferences = preferencesLocation.resolve("preferences.xml");
+        try (OutputStream fos = Files.newOutputStream(preferences)) {
+            final String pref = "<config>\n" +
+                    "    <preferences operation=\"replace\">\n" +
+                    "        <list key='plugins'>\n" +
+                    "          <entry value='baz'/>\n" +
+                    "        </list>\n" +
+                    "    </preferences>\n" +
+                    "</config>";
+            fos.write(pref.getBytes(StandardCharsets.UTF_8));
+        }
+        validatorCLI.processArguments(new String[]{"--load-preferences=" + preferences,
+                "--input", "resources/styles/standard/elemstyles.mapcss"});
+        assertEquals(Collections.singletonList("baz"), Config.getPref().getList("plugins"));
+    }
+
     /**
      * Read json objects from a file
      * @param path The file to read
