-
Bug
-
Resolution: Fixed
-
P4
-
8, 11, 17
-
b26
-
Not verified
A DESCRIPTION OF THE PROBLEM :
StreamResult(File) writes to incorrect file path if # is part of the file path
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See test case below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Write file ./output/#/dom.xml
ACTUAL -
Write file ./output
Exception in thread "main" javax.xml.transform.TransformerException: java.io.FileNotFoundException: ./output (Is a directory)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:540)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:354)
at test.Main.main(Main.java:26)
Caused by: java.io.FileNotFoundException: ./output (Is a directory)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:126)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:513)
... 2 more
---------- BEGIN SOURCE ----------
package test;
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
public class Main {
public static void main(String[] args) throws Exception {
File f = new File("./output/#/dom.xml");
f.getParentFile().mkdirs();
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
dom.appendChild(dom.createElement("root"));
Transformer tr = TransformerFactory.newInstance().newTransformer();
tr.setOutputProperty(OutputKeys.INDENT, "yes");
tr.transform(new DOMSource(dom), new StreamResult(f));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use StreamResult(OutputStream) with standard FileOutputStream instead.
FREQUENCY : always
StreamResult(File) writes to incorrect file path if # is part of the file path
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See test case below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Write file ./output/#/dom.xml
ACTUAL -
Write file ./output
Exception in thread "main" javax.xml.transform.TransformerException: java.io.FileNotFoundException: ./output (Is a directory)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:540)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:354)
at test.Main.main(Main.java:26)
Caused by: java.io.FileNotFoundException: ./output (Is a directory)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:126)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:513)
... 2 more
---------- BEGIN SOURCE ----------
package test;
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
public class Main {
public static void main(String[] args) throws Exception {
File f = new File("./output/#/dom.xml");
f.getParentFile().mkdirs();
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
dom.appendChild(dom.createElement("root"));
Transformer tr = TransformerFactory.newInstance().newTransformer();
tr.setOutputProperty(OutputKeys.INDENT, "yes");
tr.transform(new DOMSource(dom), new StreamResult(f));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use StreamResult(OutputStream) with standard FileOutputStream instead.
FREQUENCY : always
- relates to
-
JDK-8268222 javax/xml/jaxp/unittest/transform/Bug6216226Test.java failed, cannot delete file
- Resolved