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

javax.xml.parsers.DocumentBuilder Will not parse with a file that has a UNC path

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.1.1, 1.4.1
    • Fix Version/s: None
    • Component/s: xml
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      solaris_2.5.1, windows_2000

      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)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jsuttorsunw Jeff Suttor (Inactive)
                Reporter:
                rlewis Roger Lewis (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: