You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2004/10/28 11:12:03 UTC
cvs commit: ant/src/main/org/apache/tools/ant/types CommandlineJava.java PropertySet.java
peterreilly 2004/10/28 02:12:03
Modified: src/main/org/apache/tools/ant Project.java
src/main/org/apache/tools/ant/types CommandlineJava.java
PropertySet.java
Log:
Properties.propertyNames() should be used instead of .keys():
fix for previous fix - use getProperty() and not get()
fix for PropertySet
PR: 27261
Revision Changes Path
1.176 +3 -3 ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.175
retrieving revision 1.176
diff -u -r1.175 -r1.176
--- Project.java 28 Oct 2004 08:47:26 -0000 1.175
+++ Project.java 28 Oct 2004 09:12:02 -0000 1.176
@@ -830,8 +830,8 @@
Properties systemP = System.getProperties();
Enumeration e = systemP.propertyNames();
while (e.hasMoreElements()) {
- Object name = e.nextElement();
- String value = systemP.get(name).toString();
+ String name = (String) e.nextElement();
+ String value = systemP.getProperty(name);
this.setPropertyInternal(name.toString(), value);
}
}
1.58 +2 -2 ant/src/main/org/apache/tools/ant/types/CommandlineJava.java
Index: CommandlineJava.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/CommandlineJava.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- CommandlineJava.java 28 Oct 2004 08:47:26 -0000 1.57
+++ CommandlineJava.java 28 Oct 2004 09:12:02 -0000 1.58
@@ -134,8 +134,8 @@
sys = System.getProperties();
Properties p = new Properties();
for (Enumeration e = sys.propertyNames(); e.hasMoreElements();) {
- Object o = e.nextElement();
- p.put(o, sys.get(o));
+ String name = (String) e.nextElement();
+ p.put(name, sys.getProperty(name));
}
p.putAll(mergePropertySets());
for (Enumeration e = variables.elements(); e.hasMoreElements();) {
1.16 +16 -1 ant/src/main/org/apache/tools/ant/types/PropertySet.java
Index: PropertySet.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/PropertySet.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- PropertySet.java 5 Aug 2004 17:14:31 -0000 1.15
+++ PropertySet.java 28 Oct 2004 09:12:02 -0000 1.16
@@ -174,6 +174,21 @@
}
/**
+ * Convert the system properties to a hashtable.
+ * Use propertynames to get the list of properties (including
+ * default ones).
+ */
+ private Hashtable getAllSystemProperties() {
+ Hashtable ret = new Hashtable();
+ for (Enumeration e = System.getProperties().propertyNames();
+ e.hasMoreElements();) {
+ String name = (String) e.nextElement();
+ ret.put(name, System.getProperties().getProperty(name));
+ }
+ return ret;
+ }
+
+ /**
* this is the operation to get the existing or recalculated properties.
* @return
*/
@@ -181,7 +196,7 @@
Set names = null;
Project prj = getProject();
Hashtable props =
- prj == null ? System.getProperties() : prj.getProperties();
+ prj == null ? getAllSystemProperties() : prj.getProperties();
if (getDynamic() || cachedNames == null) {
names = new HashSet();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/types CommandlineJava.java
PropertySet.java
Posted by Peter Reilly <pe...@apache.org>.
Peter Reilly wrote:
> Stefan Bodewig wrote:
>
>> On Thu, 28 Oct 2004, Peter Reilly <pe...@apache.org> wrote:
>>
>>
>>> Stefan Bodewig wrote:
>>>
>>>
>>>> What if the keys/values are not Strings?
>>>>
>>>>
>>>>
>>>
>>> In this case, the "properties" are from System.getProperties() and
>>> not from Project.getProperties().... so they are strings.
>>>
>>
>>
>> Who is going to prevent System.getProperties().put(Object, Class)?
>>
>>
> Nothing...
> However, it is breaking the usage of properties, for example:
> public class Test {
> public static void main(String[] args) {
> Integer i = new Integer(10);
> System.getProperties().put(i, "10");
> System.getProperties().list(System.out);
> }
> }
Acutally:
Integer i = new Integer(10);
System.getProperties().put(i, "10");
Enumeration names = System.getProperties().propertyNames();
Also gives the java.lang.ClassCastException exception.
Since Properties.propertyNames() is the correct way to retieve the names
of the system properties, we cannot check if the user has messed up the
contents
of the properties (without always iterating over the contents and
removing invalid
keys and values and *then* calling propertyNames).
Peter
> gets an exception:
> Caused by: java.lang.ClassCastException: java.lang.Integer
> at java.util.Properties.enumerate(Properties.java:869)
> at java.util.Properties.list(Properties.java:823)
> at Test.main(Unknown Source)
>
> We could put a check in, but as it is not in the jdk for (is it 10
> years??), it
> may not be vital...
>
> Peter
>
>> Stefan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>> For additional commands, e-mail: dev-help@ant.apache.org
>>
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/types
CommandlineJava.java PropertySet.java
Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 28 Oct 2004, Peter Reilly <pe...@apache.org> wrote:
> However, it is breaking the usage of properties, for example:
I know. But still people "abused" Ant's properties that way, so I
wonder whether we need to expect people doing the same with system
properties.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/types CommandlineJava.java
PropertySet.java
Posted by Peter Reilly <pe...@apache.org>.
Stefan Bodewig wrote:
>On Thu, 28 Oct 2004, Peter Reilly <pe...@apache.org> wrote:
>
>
>>Stefan Bodewig wrote:
>>
>>
>>>What if the keys/values are not Strings?
>>>
>>>
>>>
>>>
>>In this case, the "properties" are from System.getProperties() and
>>not from Project.getProperties().... so they are strings.
>>
>>
>
>Who is going to prevent System.getProperties().put(Object, Class)?
>
>
Nothing...
However, it is breaking the usage of properties, for example:
public class Test {
public static void main(String[] args) {
Integer i = new Integer(10);
System.getProperties().put(i, "10");
System.getProperties().list(System.out);
}
}
gets an exception:
Caused by: java.lang.ClassCastException: java.lang.Integer
at java.util.Properties.enumerate(Properties.java:869)
at java.util.Properties.list(Properties.java:823)
at Test.main(Unknown Source)
We could put a check in, but as it is not in the jdk for (is it 10
years??), it
may not be vital...
Peter
>Stefan
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/types
CommandlineJava.java PropertySet.java
Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 28 Oct 2004, Peter Reilly <pe...@apache.org> wrote:
> Stefan Bodewig wrote:
>>
>>What if the keys/values are not Strings?
>>
>>
> In this case, the "properties" are from System.getProperties() and
> not from Project.getProperties().... so they are strings.
Who is going to prevent System.getProperties().put(Object, Class)?
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/types CommandlineJava.java
PropertySet.java
Posted by Peter Reilly <pe...@apache.org>.
Stefan Bodewig wrote:
>On 28 Oct 2004, <pe...@apache.org> wrote:
>
>
>
>> fix for previous fix - use getProperty() and not get()
>>
>>
>
>What if the keys/values are not Strings?
>
>
In this case, the "properties" are from System.getProperties() and not from
Project.getProperties().... so they are strings.
The issue is that System.getProperties().get() was used rather that
System.getProperties().getProperty()
get() may bypass the default resolving logic in the jdk (looking at the
code, this seems to be the
case)
Peter
>There must be a very old bug lurking in Bugzilla that was resolved by
>not assuming that the Ant properties table only contains Strings.
>
>I'm not sure whether the system properties table gets abused in a
>similar way by anybody. If so, this is a backwards incompatible
>change, I guess.
>
>Stefan
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant/types
CommandlineJava.java PropertySet.java
Posted by Stefan Bodewig <bo...@apache.org>.
On 28 Oct 2004, <pe...@apache.org> wrote:
> fix for previous fix - use getProperty() and not get()
What if the keys/values are not Strings?
There must be a very old bug lurking in Bugzilla that was resolved by
not assuming that the Ant properties table only contains Strings.
I'm not sure whether the system properties table gets abused in a
similar way by anybody. If so, this is a backwards incompatible
change, I guess.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org