You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/09/25 09:58:38 UTC

(maven-filtering) 01/01: fix: handle InvalidPathException for glob patterns on Windows

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch fix/254-glob-filter-files
in repository https://gitbox.apache.org/repos/asf/maven-filtering.git

commit 21f72b57bb7285545fb1d6dc29ab9c7615d75467
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Sep 25 09:58:05 2026 +0000

    fix: handle InvalidPathException for glob patterns on Windows
    
    On Windows, glob characters like * are illegal in file paths.
    When a glob pattern matches no files, the backward-compat fallback
    tried to resolve the pattern as a literal path via Path.resolve(),
    which throws InvalidPathException on Windows. Catch the exception
    and emit the 'no match' warning instead of crashing.
---
 .../org/apache/maven/shared/filtering/BaseFilter.java    | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java b/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java
index d5065a5..6572239 100644
--- a/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/BaseFilter.java
@@ -263,10 +263,18 @@ class BaseFilter implements DefaultFilterInfo {
                         if (matched.isEmpty()) {
                             // Backward-compat fallback: if the pattern looks like a glob but a literal
                             // file exists at that exact path, load it as-is (e.g. filter[1].properties).
-                            Path literalPath = FilteringUtils.resolveFile(basedir, filterFile);
-                            if (Files.isRegularFile(literalPath)) {
-                                matched = List.of(literalPath);
-                            } else {
+                            // On Windows, glob chars like * are illegal in paths, so resolveFile()
+                            // will throw InvalidPathException — catch it and skip the fallback.
+                            try {
+                                Path literalPath = FilteringUtils.resolveFile(basedir, filterFile);
+                                if (Files.isRegularFile(literalPath)) {
+                                    matched = List.of(literalPath);
+                                } else {
+                                    getLogger().warn("Filter glob '{}' did not match any files", filterFile);
+                                }
+                            } catch (java.nio.file.InvalidPathException e) {
+                                // Path contains OS-invalid characters (e.g. * on Windows);
+                                // it cannot be a literal file, so just warn.
                                 getLogger().warn("Filter glob '{}' did not match any files", filterFile);
                             }
                         }