Discussion:
[jira] [Commented] (XALANJ-2386) tranforming a StreamResult constructed with a File object for a path containing namespaces fails
Saad Benbouzid (JIRA)
2016-06-03 14:44:59 UTC
Permalink
[ https://issues.apache.org/jira/browse/XALANJ-2386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15314208#comment-15314208 ]

Saad Benbouzid commented on XALANJ-2386:
----------------------------------------

How come this bug isn't resolved yet ?!
We're in 2016 and the bug is still reproductible on java 8 (JDK 1.8.0_45 for me).
#wtf

{code:title=javax/xml/transform/stream/StreamResult.java}
/**
* Construct a StreamResult from a File.
*
* @param f Must a non-null File reference.
*/
public StreamResult(File f) {
//convert file to appropriate URI, f.toURI().toASCIIString()
//converts the URI to string as per rule specified in
//RFC 2396,
setSystemId(f.toURI().toASCIIString());
}
{code}
tranforming a StreamResult constructed with a File object for a path containing namespaces fails
------------------------------------------------------------------------------------------------
Key: XALANJ-2386
URL: https://issues.apache.org/jira/browse/XALANJ-2386
Project: XalanJ2
Issue Type: Bug
Components: XSLTC
Affects Versions: 2.7
Environment: Windows XP, Sun J2SE 5 or Harmony 533500
Reporter: Andrew Ferguson
Fix For: 2.5
hi,
The behaviour of the code snippet below is different depending on whether you use XalanJ 2.7.0 or the inbuilt equivalent in Sun Java 5.
If you construct a StreamResult with a java.io.File containing spaces in the name, then a wrapped FileNotFoundException is thrown because it looks for a filename with the spaces encoded as "%20"
https://bugs.eclipse.org/bugs/show_bug.cgi?id=194359
thanks,
Andrew
------------- Snippet
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerException;
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 {
try {
Document d =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
DOMSource domSource = new DOMSource(d);
StreamResult res = new StreamResult(new File("C:/A B/test.xml"));
TransformerFactory.newInstance().newTransformer().transform(domSource, res);
} catch(TransformerException te) {
if(te.getMessage().indexOf("%20")!=-1) {
System.out.println("XalanJ 2.7.0");
} else {
System.out.println("Ok"); // assuming "C:/A B/" does not exist
}
}
}
}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-***@xalan.apache.org
For additional commands, e-mail: dev-***@xalan.apache.org
Saad Benbouzid (JIRA)
2016-06-03 14:52:59 UTC
Permalink
[ https://issues.apache.org/jira/browse/XALANJ-2386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15314232#comment-15314232 ]

Saad Benbouzid commented on XALANJ-2386:
----------------------------------------

Workaround is to use another constructor of {{javax.xml.transform.stream.StreamResult}} :

{code:title=buggy.java}
File myInputFile = new File('/tmp/existing path with space');
StreamResult result = new StreamResult(myInputFile);
{code}

{code:title=workaround.java}
File myInputFile = new File('/tmp/existing path with space');
final Writer writer = new FileWriter(myInputFile);
StreamResult result = new StreamResult(writer);
{code}
tranforming a StreamResult constructed with a File object for a path containing namespaces fails
------------------------------------------------------------------------------------------------
Key: XALANJ-2386
URL: https://issues.apache.org/jira/browse/XALANJ-2386
Project: XalanJ2
Issue Type: Bug
Components: XSLTC
Affects Versions: 2.7
Environment: Windows XP, Sun J2SE 5 or Harmony 533500
Reporter: Andrew Ferguson
Fix For: 2.5
hi,
The behaviour of the code snippet below is different depending on whether you use XalanJ 2.7.0 or the inbuilt equivalent in Sun Java 5.
If you construct a StreamResult with a java.io.File containing spaces in the name, then a wrapped FileNotFoundException is thrown because it looks for a filename with the spaces encoded as "%20"
https://bugs.eclipse.org/bugs/show_bug.cgi?id=194359
thanks,
Andrew
------------- Snippet
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerException;
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 {
try {
Document d =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
DOMSource domSource = new DOMSource(d);
StreamResult res = new StreamResult(new File("C:/A B/test.xml"));
TransformerFactory.newInstance().newTransformer().transform(domSource, res);
} catch(TransformerException te) {
if(te.getMessage().indexOf("%20")!=-1) {
System.out.println("XalanJ 2.7.0");
} else {
System.out.println("Ok"); // assuming "C:/A B/" does not exist
}
}
}
}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-***@xalan.apache.org
For additional commands, e-mail: dev-***@xalan.apache.org
Gary Gregory (JIRA)
2016-06-03 16:46:59 UTC
Permalink
[ https://issues.apache.org/jira/browse/XALANJ-2386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15314389#comment-15314389 ]

Gary Gregory commented on XALANJ-2386:
--------------------------------------

{quote}
How come this bug isn't resolved yet ?!
{quote}
You are welcome to provide a patch with unit tests. That is the best chance of getting things done around here. It's not easy to learn Xalan's custom testing framework, I'll give you that!

{quote}
We're in 2016 and the bug is still reproductible on java 8 (JDK 1.8.0_45 for me).
{quote}

Why are you complaining here about an Oracle product?
tranforming a StreamResult constructed with a File object for a path containing namespaces fails
------------------------------------------------------------------------------------------------
Key: XALANJ-2386
URL: https://issues.apache.org/jira/browse/XALANJ-2386
Project: XalanJ2
Issue Type: Bug
Components: XSLTC
Affects Versions: 2.7
Environment: Windows XP, Sun J2SE 5 or Harmony 533500
Reporter: Andrew Ferguson
Fix For: 2.5
hi,
The behaviour of the code snippet below is different depending on whether you use XalanJ 2.7.0 or the inbuilt equivalent in Sun Java 5.
If you construct a StreamResult with a java.io.File containing spaces in the name, then a wrapped FileNotFoundException is thrown because it looks for a filename with the spaces encoded as "%20"
https://bugs.eclipse.org/bugs/show_bug.cgi?id=194359
thanks,
Andrew
------------- Snippet
import java.io.File;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.TransformerException;
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 {
try {
Document d =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
DOMSource domSource = new DOMSource(d);
StreamResult res = new StreamResult(new File("C:/A B/test.xml"));
TransformerFactory.newInstance().newTransformer().transform(domSource, res);
} catch(TransformerException te) {
if(te.getMessage().indexOf("%20")!=-1) {
System.out.println("XalanJ 2.7.0");
} else {
System.out.println("Ok"); // assuming "C:/A B/" does not exist
}
}
}
}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-***@xalan.apache.org
For additional commands, e-mail: dev-***@xalan.apache.org

Loading...