diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 2757866489..fa0a5b63b4 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -52,11 +52,13 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* all + * [#1196](https://github.com/pmd/pmd/issues/1196): \[core] CPD results not consistent between runs * apex * [#1542](https://github.com/pmd/pmd/pull/1542): \[apex] Include the documentation category * [#1546](https://github.com/pmd/pmd/issues/1546): \[apex] PMD parsing exception for Apex classes using 'inherited sharing' keyword * java - * [#1556](https://github.com/pmd/pmd/issues/1556): \[java] Default methods should not be considered abstract + * [#1556](https://github.com/pmd/pmd/issues/1556): \[java] Default methods should not be considered abstract * [#1578](https://github.com/pmd/pmd/issues/1578): \[java] Private field is detected as public inside nested classes in interfaces * java-bestpractices * [#658](https://github.com/pmd/pmd/issues/658): \[java] OneDeclarationPerLine: False positive for loops @@ -100,6 +102,7 @@ will also be removed. * [#1551](https://github.com/pmd/pmd/pull/1551): \[java] InvalidSlf4jMessageFormatRule should not throw NPE for enums - [Robbie Martinus](https://github.com/rmartinus) * [#1552](https://github.com/pmd/pmd/pull/1552): \[core] Upgrading Google Gson from 2.5 to 2.8.5 - [Thunderforge](https://github.com/Thunderforge) * [#1553](https://github.com/pmd/pmd/pull/1553): \[core] Upgrading System Rules dependency from 1.8.0 to 1.19.0 - [Thunderforge](https://github.com/Thunderforge) +* [#1584](https://github.com/pmd/pmd/pull/1584): \[core] Fixes 1196: inconsistencies of clones returned by different CPD executions for the same files - [Bruno Ferreira](https://github.com/bmbferreira) {% endtocmaker %} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java index 544e10dad6..d4719bb444 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java @@ -7,20 +7,31 @@ package net.sourceforge.pmd.util; import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import org.apache.commons.io.comparator.PathFileComparator; + /** * A utility class for finding files within a directory. */ public class FileFinder { private FilenameFilter filter; - private static final String FILE_SEP = System.getProperty("file.separator"); + /** + * Searches for files in a given directory. + * + * @param dir the directory to search files + * @param filter the filename filter that can optionally be passed to get files that match this filter + * @param recurse search for files recursively or not + * @return list of files from the given directory + */ public List findFilesFrom(File dir, FilenameFilter filter, boolean recurse) { this.filter = filter; List files = new ArrayList<>(); scanDirectory(dir, files, recurse); + return files; } @@ -28,18 +39,20 @@ public class FileFinder { * Implements a tail recursive file scanner */ private void scanDirectory(File dir, List list, boolean recurse) { - String[] candidates = dir.list(filter); + File[] candidates = dir.listFiles(filter); if (candidates == null) { return; } - for (int i = 0; i < candidates.length; i++) { - File tmp = new File(dir + FILE_SEP + candidates[i]); + + Arrays.sort(candidates, PathFileComparator.PATH_INSENSITIVE_COMPARATOR); + + for (File tmp : candidates) { if (tmp.isDirectory()) { if (recurse) { scanDirectory(tmp, list, true); } } else { - list.add(new File(dir + FILE_SEP + candidates[i])); + list.add(tmp); } } }