You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ralph Goers <ra...@dslextreme.com> on 2010/03/30 08:00:23 UTC

Re: PropertiesConfiguration returning duplicate values from

The constructor called load once because you specified the file name.  From what I can from the code every time you call load you are going to get another set of the properties.


On Mar 29, 2010, at 2:56 PM, Allen, Justin wrote:

> Hi,
> 
> I'm looking to get some insight on why I'm getting some unexpected
> output from the method getList() from the class PropertiesConfiguration
> as part of the commons-configuration-1.6 java lib.
> 
> This line of code produces duplicate values in the returned list loaded
> from my applications property file:
> 
> PropertiesConfiguration myAppProps= new
> PropertiesConfiguration(MY_APP_FILE);
> myAppProps.load();
> MyController ctrl = MyController.getInstance();
> ctrl.setAlertOnLamb(myAppProps.getBoolean("foo.fighter"));
> ctrl.setAlertOnRpe(myAppProps.getBoolean("bar.high"));
> ctrl.setMyBazNamesList(myAppProps.getList("baz.names"));
> 
> System.out.println("This is the baz list: " +
> myAppProps.getList("baz.names"));
> 
> 
> Application Output is:
> 
> This is the baz list: [larry, curly, moe, larry, curly, moe]
> 
> 
> This is the underlying property file which is loaded by the
> PropertiesConfiguration class:
> 
> #############################################################
> # Properties Configuration File for myApp
> #############################################################
> 
> #Set this value for foo
> foo.fighter = false
> 
> #Set this value for bar
> bar.high = false
> 
> #List of baz names
> baz.names = larry, curly, moe
> 
> 
> 
> Any reason why this would produce a list with duplicate entries? This
> doesn't appear to be normal behavior according to the documentation on
> this class. Let me know if there is any more information I can provide
> to clarify this bug, I'm getting.
> 
> Thanks for looking into this,
> 
> Justin Allen
> 
> 
> 


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


RE: PropertiesConfiguration returning duplicate values from

Posted by "Allen, Justin" <Ju...@Teradata.com>.
 
Removing the extra load method corrected the problem. Thanks for
pointing this out. 

I went back to the User Manual documentation and it does state the class
constructor does call load and the how to guide does mention you can
unionize multiple property files by calling load on multiple file. 

One could argue there should be a more explicit statement about this
side effect, but maybe a FAQ on usage issue like this would be more
helpful instead. Personally I couldn't find this issue in a more
extensive Google search or searching within the mail archives.

Thanks for the quick response and tip.


-----Original Message-----
From: Ralph Goers [mailto:ralph.goers@dslextreme.com] 
Sent: Monday, March 29, 2010 11:00 PM
To: Commons Users List
Subject: Re: PropertiesConfiguration returning duplicate values from

The constructor called load once because you specified the file name.
>From what I can from the code every time you call load you are going to
get another set of the properties.


On Mar 29, 2010, at 2:56 PM, Allen, Justin wrote:

> Hi,
> 
> I'm looking to get some insight on why I'm getting some unexpected 
> output from the method getList() from the class 
> PropertiesConfiguration as part of the commons-configuration-1.6 java
lib.
> 
> This line of code produces duplicate values in the returned list 
> loaded from my applications property file:
> 
> PropertiesConfiguration myAppProps= new 
> PropertiesConfiguration(MY_APP_FILE);
> myAppProps.load();
> MyController ctrl = MyController.getInstance(); 
> ctrl.setAlertOnLamb(myAppProps.getBoolean("foo.fighter"));
> ctrl.setAlertOnRpe(myAppProps.getBoolean("bar.high"));
> ctrl.setMyBazNamesList(myAppProps.getList("baz.names"));
> 
> System.out.println("This is the baz list: " + 
> myAppProps.getList("baz.names"));
> 
> 
> Application Output is:
> 
> This is the baz list: [larry, curly, moe, larry, curly, moe]
> 
> 
> This is the underlying property file which is loaded by the 
> PropertiesConfiguration class:
> 
> #############################################################
> # Properties Configuration File for myApp 
> #############################################################
> 
> #Set this value for foo
> foo.fighter = false
> 
> #Set this value for bar
> bar.high = false
> 
> #List of baz names
> baz.names = larry, curly, moe
> 
> 
> 
> Any reason why this would produce a list with duplicate entries? This 
> doesn't appear to be normal behavior according to the documentation on

> this class. Let me know if there is any more information I can provide

> to clarify this bug, I'm getting.
> 
> Thanks for looking into this,
> 
> Justin Allen
> 
> 
> 


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


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