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

StreamResult fails with UNC paths

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 6
    • xml
    • 1.4
    • x86
    • windows_xp
    • Verified

        FULL PRODUCT VERSION :
        java version "1.6.0_01"
        Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
        Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP [Version 5.1.2600]

        A DESCRIPTION OF THE PROBLEM :
        Transforms where the StreamResult is created with a file specified by a UNC path fail with a FileNotFoundException. The pathnreported by that exception is not the same as the path supplied to the StreamResult constructor. For example, \\sonata\test\test.xml becomes \test\test.xml

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached code supplying a UNC path as the sole argument.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        A trivial xml file should be written to the specified file.
        ACTUAL -
        Writing to \\sonata\test\test.xml
        Exception in thread "main" javax.xml.transform.TransformerException: java.io.FileNotFoundException: \test\test.xml (The system cannot find the path specified)


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "main" javax.xml.transform.TransformerException: java.io.FileNotFoundException: \test\test.xml (The system cannot find the path specified)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:491)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:298)
        at jaxp.StreamResultUNC.main(StreamResultUNC.java:37)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
        Caused by: java.io.FileNotFoundException: \test\test.xml (The system cannot find the path specified)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:463)
        ... 7 more
        ---------
        java.io.FileNotFoundException: \test\test.xml (The system cannot find the path specified)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:463)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:298)
        at jaxp.StreamResultUNC.main(StreamResultUNC.java:37)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import org.w3c.dom.Document;
        import org.w3c.dom.Element;

        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.transform.Transformer;
        import javax.xml.transform.TransformerFactory;
        import javax.xml.transform.dom.DOMSource;
        import javax.xml.transform.stream.StreamResult;
        import java.io.File;

        /** Test Windows UNC paths.
         * Universal Naming Convention paths fail.
         * Created by IntelliJ IDEA.
         * User: mthornton
         * Date: 25-Apr-2007
         * Time: 21:36:44
         * To change this template use File | Settings | File Templates.
         */
        public class StreamResultUNC
        {
        public static void main(String[] args) throws Exception {
        // create a document to write
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.newDocument();
        Element root = doc.createElement("test");
        doc.appendChild(root);
        // create an identity transform
        Transformer t = TransformerFactory.newInstance().newTransformer();
        File f = new File(args[0]);
        StreamResult result = new StreamResult(f);
        DOMSource source = new DOMSource(doc);
        System.out.println("Writing to "+f);
        t.transform(source, result);
        }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Map the share to a drive and use the drive based path instead.
        Alternatively open the file first and use the OutputStream version of the StreamResult constructor.

              nwalshsunw Norman Walsh (Inactive)
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: