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

DocumentBuilder.parse does not work on file names with spaces

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: xml
    • Labels:

      Description

      FULL PRODUCT VERSION :
      C:\Documents and Settings\flavio.FLAVIO-PC>java -version
      java version "1.6.0_06"
      Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
      Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows xp Service Pack 2

      Microsoft Windows XP [versão 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      In the following code -

      Document doc;
        
      // construtor que seta o arquivo XML
      public LeXml( String arquivo ) {
           try{
               DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
               doc = db.parse(arquivo); //here occured IOException only for Strings
           } catch (ParserConfigurationException ex) {
               System.out.println(ex.getMessage()+" 1");
           } catch (org.xml.sax.SAXException ex2){
               System.out.println(ex2.getMessage()+" 2");
           } catch (java.io.IOException ex3){
               System.out.println(ex3.getMessage()+" 3");//this exception ocurred
           }
                     
      }

      if the name of the xml file contains spaces, intantiating a Document object generates a IOException( this does not happen if take away the spaces of the names of the file). if instead of a String, we use an object of type java.io.File, it works as expected.

      more informations here:

      http://www.guj.com.br/posts/list/97223.java


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Code executes

      ACTUAL -
      IOException


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      //imports....
      public class LeXml {
      Document doc;
         
         // construtor que seta o arquivo XML
         public LeXml( String arquivo ) {
              try{
                  DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                  doc = db.parse(new java.io.File(arquivo)); //aki ta dando merda
              } catch (ParserConfigurationException ex) {
                  System.out.println(ex.getMessage()+" 1"); //sei la q erro é esse
              } catch (org.xml.sax.SAXException ex2){
                  System.out.println(ex2.getMessage()+" 2"); //esse mto menos
              } catch (java.io.IOException ex3){
                  System.out.println(ex3.getMessage()+" 3");
              }
                      
         }

      ...

      public static void main(String args[]){
              LeXml l = new LeXml("C:\\a a.xml");
       ...
      }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      doc = db.parse(arquivo);

      to

      doc = db.parse(new java.io.File(arquivo));

        Attachments

          Activity

            People

            • Assignee:
              joehw Joe Wang
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: