Another Eclipse Compiler Bug

I got compiling in DrJava using the Eclipse compiler to work last night, except that the errors never provided a source location. I thought this was because I hadn’t set the source path in the file manager, but it turned out that is not the issue. There is another bug in the Eclipse compiler: The developers use a file name in a place where a class name is expected, and because of that, the look-up of the source location always fails.

I filed a bug report for it: Bug 308256 – DiagnosticListener always supplies Diagnostic.getSource()==null

Build Identifier: ecj-3.6M6.jar

When compiling with a DiagnosticListener and encountering an error, the
provided Diagnostic always returns null for the getSource()
call.

This is because originatingFileName is being passed to
JavaFileManager.getJavaFileForInput, even though the method expects a class
name. For example, “/home/username/temp/Foo.java” is being passed as a class
name, not “Foo”.

@Override
public JavaFileObject getSource() {
try {
if (EclipseCompilerImpl.this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
return EclipseCompilerImpl.this.fileManager.getJavaFileForInput(
StandardLocation.SOURCE_PATH,
new String(originatingFileName),
JavaFileObject.Kind.SOURCE);
}
} catch (IOException e) {
// ignore
}
return null;
}


Instead of using getJavaFileForInput, which expects a class name, you could use
getJavaFileObjects, which works for a file name.

Reproducible: Always

Steps to Reproduce:
1. Just compile code using a DiagnosticListener
2. Encounter an error in a Java file.
3. Look at the return value of Diagnostic.getSource(), it is always null.

Now I don’t quite know what to do. Should I fix this bug locally and use a modified version of the Eclipse compiler in DrJava, until this bug gets fixed by the Eclipse people?

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in DrJava. Bookmark the permalink.

Leave a Reply