Copilot commented on code in PR #3394:
URL: https://github.com/apache/maven-surefire/pull/3394#discussion_r3610106384


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +238,73 @@ File createArgsFile(
             return surefireArgs;
         }
     }
+
+    /**
+     * Searches for module-info-patch.args generated by maven-compiler-plugin 
4.x.
+     * The file is expected at {@code 
target/test-classes/META-INF/maven/module-info-patch.args}
+     * or within a module subdirectory at
+     * {@code 
target/test-classes/<module>/META-INF/maven/module-info-patch.args}.
+     *
+     * @param patchFile the test classes directory (may be the module 
subdirectory)
+     * @return the module-info-patch.args file, or null if not found
+     */
+    @Nullable
+    private static File findModuleInfoPatchArgs(File patchFile) {
+        // Direct location: 
target/test-classes/<module>/META-INF/maven/module-info-patch.args
+        File argsFile = new File(patchFile, 
"META-INF/maven/module-info-patch.args");
+        if (argsFile.isFile()) {
+            return argsFile;
+        }
+        // Parent location: 
target/test-classes/META-INF/maven/module-info-patch.args
+        File parent = patchFile.getParentFile();
+        if (parent != null) {
+            argsFile = new File(parent, 
"META-INF/maven/module-info-patch.args");
+            if (argsFile.isFile()) {
+                return argsFile;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Reads the module-info-patch.args file and appends its --add-exports and 
--add-opens
+     * directives to the args builder. The --add-reads directive is handled by 
surefire itself
+     * (always adds ALL-UNNAMED) to avoid referencing modules that may be on 
the classpath
+     * rather than the module-path.
+     *

Review Comment:
   The Javadoc for `appendModuleInfoPatchArgs()` says it appends only 
`--add-exports` and `--add-opens`, but the implementation actually appends 
every non-empty, non-comment line except `--add-reads`/`--add-modules`. This 
mismatch can mislead future changes (e.g., if new directives are added to the 
compiler args file). Update the Javadoc to match the actual filtering behavior.



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java:
##########
@@ -224,4 +238,73 @@ File createArgsFile(
             return surefireArgs;
         }
     }
+
+    /**
+     * Searches for module-info-patch.args generated by maven-compiler-plugin 
4.x.
+     * The file is expected at {@code 
target/test-classes/META-INF/maven/module-info-patch.args}
+     * or within a module subdirectory at
+     * {@code 
target/test-classes/<module>/META-INF/maven/module-info-patch.args}.
+     *
+     * @param patchFile the test classes directory (may be the module 
subdirectory)
+     * @return the module-info-patch.args file, or null if not found
+     */
+    @Nullable
+    private static File findModuleInfoPatchArgs(File patchFile) {
+        // Direct location: 
target/test-classes/<module>/META-INF/maven/module-info-patch.args
+        File argsFile = new File(patchFile, 
"META-INF/maven/module-info-patch.args");
+        if (argsFile.isFile()) {
+            return argsFile;
+        }
+        // Parent location: 
target/test-classes/META-INF/maven/module-info-patch.args
+        File parent = patchFile.getParentFile();
+        if (parent != null) {
+            argsFile = new File(parent, 
"META-INF/maven/module-info-patch.args");
+            if (argsFile.isFile()) {
+                return argsFile;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Reads the module-info-patch.args file and appends its --add-exports and 
--add-opens
+     * directives to the args builder. The --add-reads directive is handled by 
surefire itself
+     * (always adds ALL-UNNAMED) to avoid referencing modules that may be on 
the classpath
+     * rather than the module-path.
+     *
+     * @param args the args builder to append to
+     * @param patchArgs the module-info-patch.args file
+     * @param moduleName the module name for the fallback --add-reads
+     * @throws IOException if the file cannot be read
+     */
+    private static void appendModuleInfoPatchArgs(StringBuilder args, File 
patchArgs, String moduleName)
+            throws IOException {
+        try (BufferedReader reader = new BufferedReader(new 
FileReader(patchArgs))) {
+            String line;

Review Comment:
   `appendModuleInfoPatchArgs()` reads `module-info-patch.args` via 
`FileReader`, which uses the platform default charset. The compiler-generated 
args file is effectively UTF-8 text; using the default charset can misparse 
non-ASCII module/package names or paths on systems with non-UTF-8 defaults. 
Prefer `Files.newBufferedReader(patchArgs.toPath(), UTF_8)` (or equivalent) to 
make the read deterministic across platforms, and drop the `FileReader` import 
accordingly.



-- 
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