On 3 December 2011 07:25, Stefan Bodewig <[email protected]> wrote:
> Hi Oliver,
>
> On 2011-12-02, <[email protected]> wrote:
>
>> Another attempt to fix the GUMP build using an ugly cast.
>> - Map<Object, Object> systemProperties = System.getProperties();
>> + // This is ugly, but it is safe because the Properties object
>> returned
>> + // by System.getProperties() (which is actually a Map<Object,
>> Object>)
>> + // contains only String keys.
>> + @SuppressWarnings("unchecked")
>> + Map<String, Object> systemProperties =
>> + (Map<String, Object>) (Object) System.getProperties();
>> MultiVariableExpander expander = new MultiVariableExpander();
>> expander.addSource("$", systemProperties);
>
> The assumption you make here may not always hold true. We've had
> several bug reports against Ant when we assumed the system properties
> would only hold string keys (or even values) and this simply was not
> true in cases where Ant code was used embedded in a larger application
> that was doing strange things. java.util.Properties will not prevent
> you from putting objects into it. I assume a commons component is at a
> bigger risk of such scenarios than an application like Ant.
That's very interesting; I suspect there are some other cases in
Commons where we have made this assumption.
[And probably in many other projects when converting to generics ...]
However, if one uses java.util.Properties.load() or void
java.util.Properties.loadXML() it should be OK, because the load
method only creates Strings?
> Even if it takes a bit longer it may be cleaner to create a new Map that
> contained a filtered view of only those properties that actually have
> string keys.
Good point.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]