Bug 301562 - [JSR269] Error in EclipseFileManager.collectAllMatchingFiles
Summary: [JSR269] Error in EclipseFileManager.collectAllMatchingFiles
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-02 12:22 EST by Dmitry Balzer CLA
Modified: 2010-03-08 12:11 EST (History)
1 user (show)

See Also:


Attachments
Proposed fix + regression tests (17.28 KB, patch)
2010-02-03 15:32 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Balzer CLA 2010-02-02 12:22:40 EST
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
Comment 1 Olivier Thomann CLA 2010-02-02 12:28:38 EST
Would you have an example where the wrong result is reported? I would add it as a regression test.
Thanks for the report.
Comment 2 Dmitry Balzer CLA 2010-02-02 13:05:52 EST
(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());
		}
	}
}
===
Comment 3 Olivier Thomann CLA 2010-02-03 15:32:16 EST
Created attachment 158095 [details]
Proposed fix + regression tests
Comment 4 Olivier Thomann CLA 2010-02-03 15:32:42 EST
Thanks for the test case.
Patch is ready.
Comment 5 Olivier Thomann CLA 2010-02-03 15:49:48 EST
Released for 3.6M6.
Regression tests added in both compiler.tools and compiler.apt tests.
Comment 6 Frederic Fusier CLA 2010-03-08 12:11:15 EST
Verified for 3.6M6 using build I20100307-2000.