Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6450078

DefaultFileManager.RegularFileObject.toUri produces bogus URI

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      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.)

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: