Hi Mike,

Am 01.02.2011 18:35, schrieb Mike Power:
Curiosity question I am seeing the ConfigurationConverter behave
differently depending on if I added an int or a string to a
configuration object.

Consider the following code:

01 Configuration confInt = new BaseConfiguration();
02 Configuration confString = new BaseConfiguration();
03 confInt.setProperty("port", 80);
04 confString.setProperty("port", "80");
05 assertEquals(80, confInt.getInt("port"));
06 assertEquals(80, confString.getInt("port"));
07
08 Properties propString =
ConfigurationConverter.getProperties(confString);
09 assertEquals("80", propString.getProperty("port"));
10
11 Properties propInt = ConfigurationConverter.getProperties(confInt);
12
13 assertEquals("80", propInt.getProperty("port"));

As you can see the code is basically duplicated one set uses an int the
other set uses a String. However an exception blows out of line 11.

'port' doesn't map to a List object: 80, a java.lang.Integer
org.apache.commons.configuration.ConversionException: 'port' doesn't map
to a List object: 80, a java.lang.Integer
at
org.apache.commons.configuration.AbstractConfiguration.getList(AbstractConfiguration.java:1144)

at
org.apache.commons.configuration.AbstractConfiguration.getList(AbstractConfiguration.java:1109)

at
org.apache.commons.configuration.ConfigurationConverter.getProperties(ConfigurationConverter.java:116)


It seems for some reason since I used an int, the ConfigurationConverter
wants to treat the property as a list. However since I actually put an
integer into the property it errors out since it can not convert a
integer to a list.

This behavior seems odd. Why does it do this?

Mike Power


the code responsible for this odd behavior is actually in AbstractConfiguration.getList(). Here a single string value is treated in a special way: it is returned as single element of a newly created list. However, for other scalar types such a conversion is not performed.

This code is pretty old, I guess it is in there from the very beginning. Probably it was just forgotten that a configuration could store other types of values, too.

If you like, you can add a bug report in Jira. The current behavior is probably not desired.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to