Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

URI's with spaces

807607Oct 13 2006 — edited Oct 21 2006
Struggling with the new Mustang in-memory compilation stuff. Looks like Java is choking on URI's for paths that include spaces:
import java.io.IOException;
import java.util.Collections;
import java.util.Locale;

import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;

public class Test {
  public static void main(String[] pArgs) throws IOException {
    for (
      JavaFileObject fileObj :
      ToolProvider.getSystemJavaCompilerTool().getStandardFileManager(
        new DiagnosticListener<JavaFileObject>() {
          public void report(Diagnostic<? extends JavaFileObject> pDiagnostic) {
            System.out.println(pDiagnostic.getMessage(Locale.getDefault()));
          }
        }
       ).list(
         StandardLocation.CLASS_PATH,
         "",
         Collections.<JavaFileObject.Kind>singleton(JavaFileObject.Kind.CLASS),
         true
       )
    ) {
      System.out.println(fileObj.toUri());
    }
  }
}
--------
<snip/>
Exception in thread "main" java.lang.IllegalArgumentException
at java.net.URI.create(URI.java:853)
at com.sun.tools.javac.util.DefaultFileManager$ZipFileObject.toUri(DefaultFileManager.java:1338)
at Test.main(Test.java:28)
Caused by: java.net.URISyntaxException: Illegal character in path at index 15: jar:/C:/Program Files/Java/jdk1.6.0/lib/tools.jar!com/sun/jarsigner/ContentSignerParameters.class
at java.net.URI$Parser.fail(URI.java:3061)
at java.net.URI$Parser.checkChars(URI.java:3234)
at java.net.URI$Parser.parsePath(URI.java:3338)
at java.net.URI$Parser.parseHierpart(URI.java:3308)
at java.net.URI$Parser.parse(URI.java:3267)
at java.net.URI.<init>(URI.java:585)
at java.net.URI.create(URI.java:851)
... 2 more
--------
This a bug or am I doing something stupid? In either case, is there a better way to get at the proper URI? I believe that I simply need to escape the spaces to '%20' somehow.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2006
Added on Oct 13 2006
6 comments
812 views