Copilot commented on code in PR #1331:
URL: 
https://github.com/apache/maven-javadoc-plugin/pull/1331#discussion_r3480724722


##########
src/main/java/org/apache/maven/plugins/javadoc/EncodingUtils.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.javadoc;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+import org.codehaus.plexus.languages.java.version.JavaVersion;
+
+class EncodingUtils {
+    /**
+     * Compute the encoding that Javadoc expects for reading and writing of 
data
+     *
+     * @return the expected encoding
+     * @since 3.12.1
+     */
+    public static Charset getExpectedEncoding() {
+        if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
+                && JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
+            return StandardCharsets.UTF_8;
+        } else {
+            return Charset.defaultCharset();
+        }
+    }

Review Comment:
   `EncodingUtils` is a pure utility class but is currently instantiable and 
extensible. Make it a non-instantiable utility (e.g., `final` class + private 
constructor) to prevent accidental construction/subclassing and to match 
typical utility-class conventions.



##########
src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java:
##########
@@ -4149,10 +4150,10 @@ private void addCommandLineOptions(Commandline cmd, 
List<String> arguments, File
         File optionsFile = new File(javadocOutputDirectory, OPTIONS_FILE_NAME);
 
         StringBuilder options = new StringBuilder();
-        options.append(StringUtils.join(arguments.iterator(), 
SystemUtils.LINE_SEPARATOR));
+        options.append(StringUtils.join(arguments.iterator(), 
System.lineSeparator()));

Review Comment:
   This change replaces the previously SecurityException-tolerant 
`SystemUtils.LINE_SEPARATOR` (which fell back when `line.separator` could not 
be read) with `System.lineSeparator()`, which can throw `SecurityException` 
under restrictive environments. If this plugin is expected to run with a 
SecurityManager / restricted property access, consider using a safe accessor 
that preserves the prior behavior (e.g., catching `SecurityException` and 
defaulting to `\"\"` or `\"\\n\"`), or rely on 
`org.apache.commons.lang3.SystemUtils.LINE_SEPARATOR` if it provides the needed 
fallback.



##########
src/main/java/org/apache/maven/plugins/javadoc/EncodingUtils.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.javadoc;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+import org.codehaus.plexus.languages.java.version.JavaVersion;
+
+class EncodingUtils {

Review Comment:
   `EncodingUtils` is a pure utility class but is currently instantiable and 
extensible. Make it a non-instantiable utility (e.g., `final` class + private 
constructor) to prevent accidental construction/subclassing and to match 
typical utility-class conventions.



##########
src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java:
##########
@@ -56,6 +56,7 @@
 
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.SystemUtils;

Review Comment:
   Since this PR reintroduces `org.apache.commons.lang3.SystemUtils` usage 
(after previously duplicating it specifically due to LANG-1365 / LANG-1384), 
ensure the project’s enforced `commons-lang3` version floor is new enough to 
contain those fixes. Otherwise the plugin may regress on newer JDKs due to 
`SystemUtils` static initialization behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to