JDK-6419926 : JSR 199: FileObject.toUri() generates URI without schema (Solaris)
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,solaris
  • CPU: generic,x86
  • Submitted: 2006-04-30
  • Updated: 2016-03-23
  • Resolved: 2011-03-08
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 JDK 7
6-poolResolved 7 b128Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
javax.tools.FileObject.toUri() generates URI without schema under Solaris OS.
A URI generated by a FileObject produced by a StandardJavaFileManager should start with 'file:'.
(Potentially it can be java.io.File problem)

test:
----------------------
import javax.tools.*;
import java.util.*;
import java.io.*;
import java.net.URI;

class test5 {
    public static void main(String[] argv){
        JavaCompilerTool compiler = ToolProvider.getSystemJavaCompilerTool();
        StandardJavaFileManager mgr = compiler.getStandardFileManager( new DiagnosticCollector<JavaFileObject>() );
        System.out.println( new File( new File(".").toURI() ).getAbsolutePath() );
        mgr.setLocation(StandardJavaFileManager.StandardLocation.CLASS_OUTPUT, 
                            Collections.singleton(new File( new File(".").toURI())));
        try {                            
            FileObject fo = mgr.getFileForOutput(StandardJavaFileManager.StandardLocation.CLASS_OUTPUT,
                                    "", URI.create("file.to.delete"), null);
            System.out.println( fo.toUri() );                                    
        } catch( IOException x ){
            x.printStackTrace(System.out);
        }
    }
}
----------------------

output under Solaris:
----------------------
it162333@~/tests>java -cp . test5
/home/it162333/tests/.
/home/it162333/tests/./file.to.delete
----------------------

output under Windows:
----------------------
Z:\tests>z:/lnks/jdk6/bin/java.exe -cp . test5
Z:\tests\.
file:/Z:/tests/./file.to.delete
----------------------
tests failed
> api/javax_tools/FileObject/index.html#All[delete0001]
> api/javax_tools/FileObject/index.html#All[getCharContent0001]
> api/javax_tools/FileObject/index.html#All[getCharContent0002]
> api/javax_tools/FileObject/index.html#All[getInputStream0001]
> api/javax_tools/FileObject/index.html#All[getLastModified0001]
> api/javax_tools/FileObject/index.html#All[getOutputStream0001]
> api/javax_tools/FileObject/index.html#All[openReader0001]
> api/javax_tools/FileObject/index.html#All[openWriter0001]
> api/javax_tools/FileObject/index.html#All[toUri0001]
> api/javax_tools/JavaFileObject/index.html#All[getKind0001]
Failing Test: javac/api/JFOTest05

Also FileObject.toUri() generates URI with one extra '.', which is not required.
Please see the attached testcase
<testcase>
import javax.tools.*;
import static javax.tools.StandardLocation.*;
import static javax.tools.JavaFileObject.Kind.*;
  
public class T6419926  {
  public static void main(String... arg) throws Exception {
      JavaCompilerTool javac =
      ToolProvider.getSystemJavaCompilerTool();
      JavaFileManager jfm = javac.getStandardFileManager(null);
      JavaFileObject jfo =
      jfm.getJavaFileForInput(CLASS_PATH,"Foo",SOURCE);
      System.out.println(jfo.toUri().toURL()); // to check - generates URI without schema.
      if(!jfo.toUri().toString().equals(jfo.toUri().resolve(
                        jfo.toUri()).toString())) // Extra dot is  not required.
          throw new Exception("Check the generated URI");
  }
}
</testcase>
Failing Tests: javac/api/JFOTest05, javac/api/JFOTest06
failing testcases: javac/api/JavaFileObject/JFOTest05 , javac/api/JavaFileObject/JFOTest06

Comments
javac/api/JavaFileObject/JFOTest06 fails with given exception on Linux / Ubuntu 12.04, i686, JDK 1.6.0_71 Exception in thread "main" java.lang.Exception: Generated uri is wrong at JFOTest06.main(JFOTest06.java:26)
13-11-2013

EVALUATION Code already works, "fix" is just to add test to repo.
14-01-2011

EVALUATION Test program (updated for current API) now shows that the code is working correctly and generating file: schema as intended. Here is the updated test program ------------------------------------------ import javax.tools.*; import java.util.*; import java.io.*; class T6419926 { public static void main(String[] argv) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager mgr = compiler.getStandardFileManager( new DiagnosticCollector<JavaFileObject>(), null, null); System.out.println( new File( new File(".").toURI() ).getAbsolutePath() ); mgr.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(new File("."))); try { FileObject fo = mgr.getFileForOutput(StandardLocation.CLASS_OUTPUT, "", "file.to.delete", null); System.out.println( fo.toUri() ); } catch( IOException x ){ x.printStackTrace(System.out); } } } --------------------------------------------
03-09-2009

EVALUATION 6411310 has been fixed.
07-12-2006

EVALUATION This is a side-effect of trying to keep URIs relative for diagnostics. We cannot address this until 6411310 is fixed.
30-04-2006