Community
Participate
Working Groups
Build Identifier: 20090920-1017 The EclipseFileManager.collectAllMatchingFiles function contains an error, because of which false results are returned: === if (f.isDirectory() && recurse) { collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector); } else { final Kind kind = getKind(f); if (kinds.contains(kind)) { // In the following code line, 'f' variable must be used instead of currentFile! // We are iterating over a file now, but adding a parent directory // instead of the file to the list collector.add(new EclipseFileObject(normalizedPackageName + currentFile.getName(), currentFile.toURI(), kind, this.charset)); } } === Reproducible: Always Steps to Reproduce: Found the bug in code
Would you have an example where the wrong result is reported? I would add it as a regression test. Thanks for the report.
(In reply to comment #1) > Would you have an example where the wrong result is reported? I would add it as > a regression test. > Thanks for the report. Hello, for example, if you have different .java files in some directory, then the following code will print out just the directory name many times instead of file names: === public class EclipseFileManagerTest { @SuppressWarnings({ "unchecked", "restriction" }) public static void main(String[] args) throws IOException { StandardJavaFileManager fileManager = new org.eclipse.jdt.internal.compiler.tool.EclipseFileManager(null, null); LinkedList<File> fins = new LinkedList<File>(); fins.add(new File("C:\\CheckDepBin\\1\\autoCheckOut\\src")); JavaFileManager.Location sourceLoc = javax.tools.StandardLocation.SOURCE_PATH; fileManager.setLocation(sourceLoc, fins); HashSet<JavaFileObject.Kind> fileTypes = new HashSet<JavaFileObject.Kind>(); fileTypes.add(JavaFileObject.Kind.SOURCE); Iterable<? extends JavaFileObject> compilationUnits = fileManager.list( sourceLoc, "", fileTypes, true); Iterator it = compilationUnits.iterator(); while (it.hasNext()) { System.out.println(it.next()); } } } ===
Created attachment 158095 [details] Proposed fix + regression tests
Thanks for the test case. Patch is ready.
Released for 3.6M6. Regression tests added in both compiler.tools and compiler.apt tests.
Verified for 3.6M6 using build I20100307-2000.