DefaultFileManager.RegularFileObject.toUri produces bogus URI

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P2
    • None
    • Affects Version/s: 6
    • Component/s: tools
    • None
    • x86
    • linux

      When receiving error diagnostics from the compiler:

      Diagnostic<? extends JavaFileObject> d;
      URI u = d.getSource().toUri();
      File f = new File(u);

      does not work. You need to use e.g.

      File f = new File(u.toString());

      since the "URI" is just a pathname, not a real 'file'-protocol URI.

      In j2se/src/share/classes/com/sun/tools/javac/util/DefaultFileManager.java, it can be seen that the impl of RegularFileObject.toUri() [BTW why the inconsistent capitalization vs. File.toURI?] is incorrect:

              public URI toUri() {
                  try {
                      return new URI(f.getPath());
                  } catch (URISyntaxException ex) {
                      return f.toURI();
                  }
              }

      which should read simply:

              public URI toUri() {
                  return f.toURI();
              }

      Similarly, ZipFileObject gets it wrong too:

              public URI toUri() {
                  String zipName = new File(getZipName()).toURI().getPath();
                  String entryName = getZipEntryName();
                  return URI.create("jar:" + zipName + "!" + entryName);
              }

      should read:

              public URI toUri() {
                  String zipName = new File(getZipName()).toURI().toString();
                  String entryName = getZipEntryName();
                  return URI.create("jar:" + zipName + "!" + entryName);
              }

      (Not sure whether URI.toString() is appropriate here or whether e.g. URI.toASCIIString() should be used.)

            Assignee:
            Peter Ahe
            Reporter:
            Jesse Glick (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: