[ http://issues.apache.org/jira/browse/FTPSERVER-41?page=all ]
Niklas Gustavsson closed FTPSERVER-41.
--------------------------------------
Resolution: Fixed
Fixed by Sergey in rev 406964
> PropertiesConfiguration constructor can produce misleading results
> ------------------------------------------------------------------
>
> Key: FTPSERVER-41
> URL: http://issues.apache.org/jira/browse/FTPSERVER-41
> Project: FtpServer
> Issue Type: Bug
> Reporter: John Wood
> Priority: Minor
> Attachments: patch.txt
>
>
> I was using the PropertiesConfiguration class to manually set properties in
> code (to save having a configuration file).
> To do this I used the PropertiesConfiguration(Properties prop) constructor
> which allows you to provide your own Properties class:
> Properties properties = new Properties();
> // Trying to set my own "SIZE" command handler
> properties.setProperty("config.command-factory.command.SIZE",
> "com.foo.MySizeHandler");
> PropertiesConfiguration config = new PropertiesConfiguration(properties);
> new FtpServer(new IFtpConfig(config)).start();
>
> However this doesn't work as expected. The problem appears to be in the
> PropertiesConfiguration consructor:
> /**
> * Constructor - set the properties.
> */
> public PropertiesConfiguration(Properties prop) {
> this.prop = new Properties(prop);
> }
> The problem is that this uses the Properties(Properties prop) constructor.
> This constructor is used to specify *defaults* which are used if the looked
> up key cannot be found. It does NOT simply use the input properties and copy
> them into itself. So, for example if you do this:
> Properties a = new Properties();
> a.setProperty("foo", "bah");
> a.setProperty("abc", "xyz");
> System.out.println(a.size());
> Properties b = new Properties(a);
> System.out.println(b.size());
>
> The result will be:
>
> 2
> 0
> i.e., the keys are not actually present in the second Properties object when
> you call size() or keys() etc.
> This causes problems in the CommandFactory.configure() where it ultimately
> calls Properties.keys(). If the Properties object is initialised as described
> above then this returns an empty list.
> My suggestion is to change the PropertiesConfiguration constructor so that it
> actually manually adds each of the keys to the internally stored Properties
> object.
>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira