Remove an optimization on PathSelector producing false negatives - #12623
Conversation
… false negative. It is safe to use an exclude filter for directory during `FileVisitor` transversal, but it is unsafe to use an include filter because of the need to traverse parents first.
gnodet
left a comment
There was a problem hiding this comment.
Review: APPROVE ✅
Well-reasoned fix that removes the unsafe include-based directory pre-filtering optimization from DirectoryPrefiltering. The rationale is sound: excluding directories is safe (if a directory matches an exclude, all files within are excluded), but include-based filtering is inherently unsafe because FileVisitor must enter parent directories before discovering matching children. For example, with include pattern **/*foo*/**, the old code would reject directory org/ because it doesn't contain "foo", preventing discovery of org/foo/ and files beneath it.
The fix correctly:
- Removes the
ignoreIncludesfield and all include-based logic - Simplifies
matches()to accept any directory not explicitly excluded - Updates
simplify()to returnINCLUDES_ALLwhen no excludes exist - Flips the appropriate test assertions with clear explanatory comments
The trade-off (slightly more directory traversal for correctness) is the right call, especially since file-level includes/excludes remain unchanged. The exclude-based filtering (retained) handles the most common performance case (skipping .git, target, etc.).
Minor nit: A couple of small language issues in the test comments — "Before to match" → "In order to match" / "Before matching", and "Same reason than above" → "Same reason as above". These are cosmetic only.
Reviewed via automated review loop · Feedback? Tag @gnodet
Forward-port of #12623 from maven-4.0.x to master. Removes the unsafe include-based directory pre-filtering optimization from PathSelector.DirectoryPrefiltering. Using exclude filters for directory traversal is safe, but using include filters causes false negatives because parent directories need to be traversed first. Author: Martin Desruisseaux (@desruisseaux) Closes #12624
Remove an optimization on
PathSelectorwhich was sometime producing false negatives. It is safe to use an exclude filter for directories duringFileVisitortransversal, but it is unsafe to use an include filter because of the need to traverse parents first.