ebourg      2004/07/12 07:40:54

  Modified:    configuration/src/java/org/apache/commons/configuration
                        XMLConfiguration.java
  Log:
  Fixed bug 29722 (addProperty throws a NPE in DOMConfiguration)
  
  Revision  Changes    Path
  1.5       +20 -15    
jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java
  
  Index: XMLConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/XMLConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLConfiguration.java     12 Jul 2004 12:14:38 -0000      1.4
  +++ XMLConfiguration.java     12 Jul 2004 14:40:54 -0000      1.5
  @@ -81,11 +81,20 @@
   
       /**
        * Empty construtor.  You must provide a file/fileName
  -     * and call the load method
  -     *
  +     * to save the configuration.
        */
       public XMLConfiguration()
       {
  +        // build an empty document.
  +        DocumentBuilder builder = null;
  +        try {
  +            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  +        } catch (ParserConfigurationException e) {
  +            throw new ConfigurationRuntimeException(e.getMessage(), e);
  +        }
  +
  +        document = builder.newDocument();
  +        document.appendChild(document.createElement("configuration"));
       }
   
       /**
  @@ -126,19 +135,19 @@
           }
           catch (IOException de)
           {
  -            throw new ConfigurationException("Could not load from " + 
file.getAbsolutePath());
  +            throw new ConfigurationException("Could not load from " + 
file.getAbsolutePath(), de);
           }
           catch (ParserConfigurationException ex)
           {
  -            throw new ConfigurationException("Could not configure parser");
  +            throw new ConfigurationException("Could not configure parser", ex);
                }
           catch (FactoryConfigurationError ex)
           {
  -            throw new ConfigurationException("Could not create parser");
  +            throw new ConfigurationException("Could not create parser", ex);
           }
           catch (SAXException ex)
           {
  -            throw new ConfigurationException("Error parsing file " + 
file.getAbsolutePath());
  +            throw new ConfigurationException("Error parsing file " + 
file.getAbsolutePath(), ex);
                }
   
           initProperties(document.getDocumentElement(), new StringBuffer());
  @@ -204,13 +213,9 @@
           NamedNodeMap attributes = element.getAttributes();
           for (int i = 0; i < attributes.getLength(); ++i)
           {
  -            Node node = attributes.item(i);
  -            if (node instanceof Attr)
  -            {
  -                Attr attr = (Attr) node;
  -                String attrName = hierarchy + '[' + ATTRIB_MARKER + attr.getName() 
+ ']';
  -                super.addProperty(attrName, attr.getValue());
  -            }
  +            Attr attr = (Attr) attributes.item(i);
  +            String attrName = hierarchy + '[' + ATTRIB_MARKER + attr.getName() + 
']';
  +            super.addProperty(attrName, attr.getValue());
           }
       }
   
  @@ -441,7 +446,7 @@
   
       /**
        * Returns the fileName.
  -     * 
  +     *
        * @return String
        */
       public String getFileName()
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to