JDK-6420409 : JSR 199: StandardFileManager: cannot set CLASS_PATH location
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-05-02
  • Updated: 2012-03-22
  • Resolved: 2006-05-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b85Fixed
Related Reports
Relates :  
Description
The class path for the compiler cannot be set by StandartFileManager.setLocation(CLASS_PATH, ...) method. I reproduce the failure under JDK b82. Please see an example below:
===Compiler.java===
import java.util.Collections;
import javax.tools.JavaCompilerTool;
import static javax.tools.JavaCompilerTool.*;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardJavaFileManager.StandardLocation;
import javax.tools.ToolProvider;

public class Compiler {
    
    public static void main(String[] argv) {
    	JavaCompilerTool compiler = 
    	    	ToolProvider.getSystemJavaCompilerTool();
        StandardJavaFileManager fileManager = 
    	    	compiler.getStandardFileManager(null);
        fileManager.setLocation(StandardLocation.CLASS_PATH,
               Collections.singleton(
    	       new File("classes/")));
        Iterable<? extends JavaFileObject> compilationUnits =
               fileManager.getJavaFileObjectsFromStrings(
    	       Collections.singleton("B.java"));
        compiler.getTask(null, fileManager, null, null, null, 
    	    	compilationUnits).run();
    	
    }    
}
====
====B.java (in the same directory as Compiler.java===
public class  B { { new A(); } }
====
====A.java (in the 'classes' directory===
public class A {}
====
====run.sh===
JDK=/java/re/jdk/6.0/latest/binaries/solaris-sparc
echo Compile Compiler.java...
$JDK/bin/javac Compiler.java
echo Invoke Compiler...
$JDK/bin/java Compiler
echo Set classpath externally and invoke compiler again...
$JDK/bin/java -cp classes:. Compiler
====
Results:
---
ag153348@oink$ . run.sh
Compile Compiler.java...
Invoke Compiler...
B.java:1: cannot find symbol
symbol  : class A
location: class B
public class  B { { new A(); } }
                        ^
1 error
Set classpath externally and invoke compiler again...
ag153348@oink$
---
It seems that the class path passed to the JavaCompilerTool via option "-cp" works fine. Currently, we use this way as a workaround.

Comments
SUGGESTED FIX Index: j2se/src/share/classes/com/sun/tools/javac/util/DefaultFileManager.java --- /tmp/geta29457 2006-05-02 00:32:32.743284097 -0700 +++ DefaultFileManager.java 2006-05-01 16:53:00.000000000 -0700 @@ -878,11 +878,12 @@ } public void setLocation(JavaFileManager.Location location, Iterable<? extends File> path) { + paths.lazy(); if (location == CLASS_OUTPUT) classOutDir = getDirectory(path, D); else if (location == SOURCE_OUTPUT) sourceOutDir = getDirectory(path, S); - else + paths.setPathForLocation(location, path); } // where @@ -907,6 +908,7 @@ } public Iterable<? extends File> getLocation(Location location) { + paths.lazy(); if (location == CLASS_OUTPUT) { return (getClassOutDir() == null ? null : List.of(getClassOutDir())); } else if (location == SOURCE_OUTPUT) { @@ -916,6 +918,7 @@ } public Iterable<? extends File> getEffectiveLocation(Location location) { + paths.lazy(); if (location == CLASS_PATH) return paths.classSearchPath(); else if (location == SOURCE_PATH)
02-05-2006

EVALUATION I noticed this problem my self during work on a different bug. I had to fix it to move on with the other issue.
02-05-2006