Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2182

Incorrect URL (systemId) handling when running with Sun JRE 1.5.0 or above

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • 2.6
    • 2.7
    • transformation
    • None
    • Windows XP SP2, Sun JDK 1.5.0_01, Xalan 2.6.0

    Description

      When running the following piece of code:
      Transformer identity = TransformerFactory.newInstance().newTransformer();
      identity.setOutputProperty("method", "xml");
      identity.setOutputProperty("indent", "yes");
      identity.transform(src, new StreamResult(new File("file.xml")));

      on a Sun JRE 1.5.0 or above, Xalan is unable to create a new file and thus throws a TransformerException.

      This is caused by lines 225-235 in Xalan's TransformerIdentityImpl.java:
      String fileURL = sresult.getSystemId();

      if (fileURL.startsWith("file:///"))
      {
      if (fileURL.substring(8).indexOf(":") >0)
      fileURL = fileURL.substring(8);
      else
      fileURL = fileURL.substring(7);
      }

      m_outputStream = new java.io.FileOutputStream(fileURL);

      As of JRE 1.5.0 Sun now generates URIs in a different way in StreamResult (see StreamResult.setSystemId()), an therefore the URI will start with file:/ instead of file:///. Thus FileOutputStream will not be able to open the file anymore, since the if-block never executes.

      The suggested fix is to change the code to the following:
      String fileURL = sresult.getSystemId();

      File file = new File(new URI(fileURL));
      m_outputStream = new java.io.FileOutputStream(file);

      Attachments

        Activity

          People

            Unassigned Unassigned
            ricq Rick Riemer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: