From e9e614a4644288148abe6cb6fae3112e25a86d2d Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Tue, 06 Oct 2026 06:58:49 +0000
Subject: [PATCH] [#1159] Keep administrator-typed DNs intact in dsconfig batch lines, tools.properties and the SDK LDAPUrl (#1166)

---
 opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java |   41 ++++++++++++++++++++++++++++++++---------
 1 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
index 548cb3c..043ab8a 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ArgumentParser.java
@@ -23,10 +23,18 @@
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.util.StaticUtils.*;
 
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
+import java.io.StringReader;
+import java.nio.ByteBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -411,10 +419,7 @@
         try {
             final Properties argumentProperties = new Properties();
             final String scriptName = getScriptName();
-            final Properties p = new Properties();
-            try (final FileInputStream fis = new FileInputStream(propertiesFilePath)) {
-                p.load(fis);
-            }
+            final Properties p = loadPropertiesFile(propertiesFilePath);
 
             for (final Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) {
                 final String currentPropertyName = (String) e.nextElement();
@@ -441,6 +446,26 @@
     }
 
     /**
+     * Reads a properties file as UTF-8, or as ISO-8859-1, which earlier releases used, when it is
+     * not valid UTF-8. A backslash keeps its meaning in the properties format and must be doubled.
+     */
+    private static Properties loadPropertiesFile(final String path) throws IOException {
+        final byte[] content = Files.readAllBytes(Paths.get(path));
+        // A UTF-8 byte order mark is skipped before decoding, so that the ISO-8859-1 fallback skips it too.
+        final int bom = content.length >= 3 && content[0] == (byte) 0xEF && content[1] == (byte) 0xBB
+                && content[2] == (byte) 0xBF ? 3 : 0;
+        String text;
+        try {
+            text = UTF_8.newDecoder().decode(ByteBuffer.wrap(content, bom, content.length - bom)).toString();
+        } catch (final CharacterCodingException e) {
+            text = new String(content, bom, content.length - bom, ISO_8859_1);
+        }
+        final Properties properties = new Properties();
+        properties.load(new StringReader(text));
+        return properties;
+    }
+
+    /**
      * Retrieves the argument with the specified long identifier.
      *
      * @param longID
@@ -1268,10 +1293,8 @@
             final boolean requirePropertiesFile) throws ArgumentException {
         Properties argumentProperties = null;
 
-        try (final FileInputStream fis = new FileInputStream(propertiesFile)) {
-            final Properties p = new Properties();
-            p.load(fis);
-            argumentProperties = p;
+        try {
+            argumentProperties = loadPropertiesFile(propertiesFile);
         } catch (final Exception e) {
             if (requirePropertiesFile) {
                 final LocalizableMessage message =

--
Gitblit v1.10.0