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:15:58 UTC

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

     [ 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