JDK-4880236 : javax.xml.parsers.DocumentBuilder Will not parse with a file that has a UNC path
  • Type: Enhancement
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 1.1.1,1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_2.5.1,windows_2000
  • CPU: generic,x86
  • Submitted: 2003-06-18
  • Updated: 2012-04-25
  • Resolved: 2007-01-18
Related Reports
Duplicate :  
Description
Name: rl43681			Date: 06/17/2003


A DESCRIPTION OF THE REQUEST :
Using a javax.xml.parsers.DocumentBuilder to parse an xml file, one cannot utilize the parse function which takes a java.io.File as an argument if the path of the File is a MS Windows UNC (network) path.

JUSTIFICATION :
This enhancement is necessary because often people will need to parse XML files which do not reside on their local machine, but can be accessed on their MS Windows network.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would like to execute the following lines of code with the path of the fileHandler being a UNC path and not recieve an IOException.

java.io.File fileHandler = new java.io.File("\\\\Network_name\\Share_name\\file_name.xml");
javax.xml.parsers.DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

try {
   javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
   org.w3c.dom.Document xmlDoc = builder.parse(fileHandler);
}
catch (SAXException sxe) {
   System.err.println("SaxException");
} catch (ParserConfigurationException pce) {
   System.err.println("ParserConfigurationException");
} catch (IOException ioe) {
   System.err.println("IOException");
}
I get an IO exception trying to run code similar to the following:

java.io.File fileHandler = new java.io.File("\\\\Network_name\\Share_name\\file_name.xml");
javax.xml.parsers.DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

try {
   javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
   org.w3c.dom.Document xmlDoc = builder.parse(fileHandler);
}
catch (SAXException sxe) {
   System.err.println("SaxException");
} catch (ParserConfigurationException pce) {
   System.err.println("ParserConfigurationException");
} catch (IOException ioe) {
   System.err.println("IOException");
}

---------- BEGIN SOURCE ----------
/* The following source code will run if you simply replace the String being used to construct the java.io.File with a valid UNC string */

java.io.File fileHandler = new java.io.File("\\\\Network_name\\Share_name\\file_name.xml");
javax.xml.parsers.DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

try {
   javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
   org.w3c.dom.Document xmlDoc = builder.parse(fileHandler);
}
catch (SAXException sxe) {
   System.err.println("SaxException");
} catch (ParserConfigurationException pce) {
   System.err.println("ParserConfigurationException");
} catch (IOException ioe) {
   System.err.println("IOException");
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
/** Since the java 2 sdk java.io.* package is keen on UNC paths the following workaroung is quite simple and effective*/

java.io.File fileHandler = new java.io.File("\\\\Network_name\\Share_name\\file_name.xml");
javax.xml.parsers.DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

try {
   javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
   //Create a new FileInputStream from the file handler
   java.io.FileInputStream FIS = new java.io.FileInputStream(fileHandler);
   //The parse function takes an InputStream as well
   org.w3c.dom.Document xmlDoc = builder.parse(FIS);
}
catch (SAXException sxe) {
   System.err.println("SaxException");
} catch (ParserConfigurationException pce) {
   System.err.println("ParserConfigurationException");
} catch (IOException ioe) {
   System.err.println("IOException");
}
(Review ID: 183499) 
======================================================================

Comments
EVALUATION will be looked into after feature freeze. ###@###.### 2003-07-25
25-07-2003