You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Fabien Nisol (JIRA)" <ji...@apache.org> on 2011/06/10 20:13:58 UTC

[jira] [Created] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
----------------------------------------------------------------------------------------------

                 Key: CONFIGURATION-452
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
             Project: Commons Configuration
          Issue Type: Bug
          Components: Expression engine
    Affects Versions: 1.6
         Environment: all
            Reporter: Fabien Nisol


The following code does not work as expected
{code:title=Bug.java|borderStyle=solid}
public class Bug {

	public static void main(String[] args) {
		try {
			XMLConfiguration config = new XMLConfiguration();
			// works
			config.setProperty("test.property[@attribute]", "value");
			config.setExpressionEngine(new XPathExpressionEngine());
			// does not work
			config.setProperty("property/@attribute2", "value2");
			config.save(System.out);
		} catch (ConfigurationException e) {
			// @FIXME Traitement d'exception par defaut
			throw new RuntimeException(e);
		}

	}

}
{code}

hangs with the following exception:


Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
	at Bug.main(Bug.java:29)



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fabien Nisol updated CONFIGURATION-452:
---------------------------------------

    Description: 
The following code does not work as expected
{code:title=Bug.java|borderStyle=solid}
public class Bug {

	public static void main(String[] args) {
		try {
			XMLConfiguration config = new XMLConfiguration();
			// works
			config.setProperty("test.property[@attribute]", "value");
			config.setExpressionEngine(new XPathExpressionEngine());
			// works
			config.setProperty("test/property[@attribute]", "value");
			// does not work
			config.setProperty("test/property/@attribute2", "value2");
			config.save(System.out);
		} catch (ConfigurationException e) {
			// @FIXME Traitement d'exception par defaut
			throw new RuntimeException(e);
		}

	}

}
{code}

hangs with the following exception:


Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
	at Bug.main(Bug.java:29)

the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.


  was:
The following code does not work as expected
{code:title=Bug.java|borderStyle=solid}
public class Bug {

	public static void main(String[] args) {
		try {
			XMLConfiguration config = new XMLConfiguration();
			// works
			config.setProperty("test.property[@attribute]", "value");
			config.setExpressionEngine(new XPathExpressionEngine());
			// does not work
			config.setProperty("property/@attribute2", "value2");
			config.save(System.out);
		} catch (ConfigurationException e) {
			// @FIXME Traitement d'exception par defaut
			throw new RuntimeException(e);
		}

	}

}
{code}

hangs with the following exception:


Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
	at Bug.main(Bug.java:29)




> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			// works
> 			config.setProperty("test/property[@attribute]", "value");
> 			// does not work
> 			config.setProperty("test/property/@attribute2", "value2");
> 			config.save(System.out);
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13051726#comment-13051726 ] 

Oliver Heger commented on CONFIGURATION-452:
--------------------------------------------

Thanks for reporting this.

This is probably not trivial to fix because the XPATH expression passed to setProperty() has to be interpreted to find the parent of the selected node. Is there a way in XPATH to retrieve the parent of an expression?

Will have to think about it and have a look at the XPATH spec. Ideas or even patches are welcome.

> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
>                         // does not work
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13052158#comment-13052158 ] 

Fabien Nisol commented on CONFIGURATION-452:
--------------------------------------------

The following scenario si probably not the best concerning performance, but it maybe worth a try:

# check if the xpath expression leads to an existing node
## if it does, simply modify it
# if it does not
## decompose the xpath into sub-paths using "/"
## recompose the path, one after the other
## when the element cannot be found, create it

However, the rule to recreate the node could be quite complex. 

For example:

{code}
<property>
  <to>
  </to>
</property>
{code}

calling setProperty("/property/to[@set='a_selector']/@attribute","a_value");

would need to create a @set attribute with the value 'a_selector' , and then add an attribute '@attribute' with the value 'a_value'

{code}
<property>
  <to set="a_selector" attribute="a_value"/>
</property>
{code}

I agree, all this seem easier to say than to realize !





> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
>                         // does not work
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fabien Nisol updated CONFIGURATION-452:
---------------------------------------

    Description: 
The following code does not work as expected
{code:title=Bug.java|borderStyle=solid}
public class Bug {

	public static void main(String[] args) {
		try {
			XMLConfiguration config = new XMLConfiguration();
			// works
			config.setProperty("test.property[@attribute]", "value");
			config.setExpressionEngine(new XPathExpressionEngine());
			config.save(System.out);
			// works
			config.setProperty("test/property/@attribute", "value");
			config.setProperty("test/property/@attribute2", "value");
		} catch (ConfigurationException e) {
			// @FIXME Traitement d'exception par defaut
			throw new RuntimeException(e);
		}

	}
}
{code}

hangs with the following exception:


Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
	at Bug.main(Bug.java:29)

the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.


  was:
The following code does not work as expected
{code:title=Bug.java|borderStyle=solid}
public class Bug {

	public static void main(String[] args) {
		try {
			XMLConfiguration config = new XMLConfiguration();
			// works
			config.setProperty("test.property[@attribute]", "value");
			config.setExpressionEngine(new XPathExpressionEngine());
			// works
			config.setProperty("test/property[@attribute]", "value");
			// does not work
			config.setProperty("test/property/@attribute2", "value2");
			config.save(System.out);
		} catch (ConfigurationException e) {
			// @FIXME Traitement d'exception par defaut
			throw new RuntimeException(e);
		}

	}

}
{code}

hangs with the following exception:


Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
	at Bug.main(Bug.java:29)

the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.



> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oliver Heger resolved CONFIGURATION-452.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.7

Marking this issue as fixed because the reported problem should be solved. Feel free to reopen - or create a new issue - if you encounter further problems.

> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>            Assignee: Oliver Heger
>             Fix For: 1.7
>
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
>                         // does not work
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fabien Nisol updated CONFIGURATION-452:
---------------------------------------

    Description: 
The following code does not work as expected
{code:title=Bug.java|borderStyle=solid}
public class Bug {

	public static void main(String[] args) {
		try {
			XMLConfiguration config = new XMLConfiguration();
			// works
			config.setProperty("test.property[@attribute]", "value");
			config.setExpressionEngine(new XPathExpressionEngine());
			config.save(System.out);
			// works
			config.setProperty("test/property/@attribute", "value");
                        // does not work
			config.setProperty("test/property/@attribute2", "value");
		} catch (ConfigurationException e) {
			// @FIXME Traitement d'exception par defaut
			throw new RuntimeException(e);
		}

	}
}
{code}

hangs with the following exception:


Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
	at Bug.main(Bug.java:29)

the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.


  was:
The following code does not work as expected
{code:title=Bug.java|borderStyle=solid}
public class Bug {

	public static void main(String[] args) {
		try {
			XMLConfiguration config = new XMLConfiguration();
			// works
			config.setProperty("test.property[@attribute]", "value");
			config.setExpressionEngine(new XPathExpressionEngine());
			config.save(System.out);
			// works
			config.setProperty("test/property/@attribute", "value");
			config.setProperty("test/property/@attribute2", "value");
		} catch (ConfigurationException e) {
			// @FIXME Traitement d'exception par defaut
			throw new RuntimeException(e);
		}

	}
}
{code}

hangs with the following exception:


Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
	at Bug.main(Bug.java:29)

the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.



> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
>                         // does not work
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13072989#comment-13072989 ] 

Oliver Heger commented on CONFIGURATION-452:
--------------------------------------------

A fix was committed in revision 1152343. XPathExpressionEngine can now deal with keys for adding or setting properties which do not have to contain a whitespace. It tries to guess the location where to insert the new nodes.

I am not sure whether this fixes all problems or works with all possible keys. It would be good if you could give it a try. Simple scenarios as in your example should be supported now; I have added a new unit test class to verify this.

I still have to update the Javadocs and the documentation accordingly.

> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>            Assignee: Oliver Heger
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
>                         // does not work
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Fabien Nisol (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13072996#comment-13072996 ] 

Fabien Nisol commented on CONFIGURATION-452:
--------------------------------------------

Thanks, I will test this revision as soon as I am back working on the project that needed that :P

> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>            Assignee: Oliver Heger
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
>                         // does not work
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CONFIGURATION-452) HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13054048#comment-13054048 ] 

Oliver Heger commented on CONFIGURATION-452:
--------------------------------------------

Yes, this is the reason why it was never implemented ;-)

I am currently busy with other things, but this issue is on my radar. I will continue thinking about a solution.

> HierarchicalConfiguration with XPathExpressionEngine does not work when setting a new property
> ----------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-452
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-452
>             Project: Commons Configuration
>          Issue Type: Bug
>          Components: Expression engine
>    Affects Versions: 1.6
>         Environment: all
>            Reporter: Fabien Nisol
>
> The following code does not work as expected
> {code:title=Bug.java|borderStyle=solid}
> public class Bug {
> 	public static void main(String[] args) {
> 		try {
> 			XMLConfiguration config = new XMLConfiguration();
> 			// works
> 			config.setProperty("test.property[@attribute]", "value");
> 			config.setExpressionEngine(new XPathExpressionEngine());
> 			config.save(System.out);
> 			// works
> 			config.setProperty("test/property/@attribute", "value");
>                         // does not work
> 			config.setProperty("test/property/@attribute2", "value");
> 		} catch (ConfigurationException e) {
> 			// @FIXME Traitement d'exception par defaut
> 			throw new RuntimeException(e);
> 		}
> 	}
> }
> {code}
> hangs with the following exception:
> Exception in thread "main" java.lang.IllegalArgumentException: prepareAdd: Passed in key must contain a whitespace!
> 	at org.apache.commons.configuration.tree.xpath.XPathExpressionEngine.prepareAdd(XPathExpressionEngine.java:223)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.addPropertyDirect(HierarchicalConfiguration.java:371)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.addPropertyDirect(AbstractHierarchicalFileConfiguration.java:140)
> 	at org.apache.commons.configuration.HierarchicalConfiguration.setProperty(HierarchicalConfiguration.java:749)
> 	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.setProperty(AbstractHierarchicalFileConfiguration.java:158)
> 	at Bug.main(Bug.java:29)
> the setProperty() method does not work if the property have to be added. This behavior is not really wanted, because in some generic cases, we don't know if the property is set or not before trying to set it.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira