Browse Source

propertyset threw NPE with nested, mapped propertysets.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278290 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
c09b4ad628
4 changed files with 57 additions and 14 deletions
  1. +2
    -0
      WHATSNEW
  2. +39
    -0
      src/etc/testcases/types/propertyset.xml
  3. +8
    -14
      src/main/org/apache/tools/ant/types/PropertySet.java
  4. +8
    -0
      src/testcases/org/apache/tools/ant/types/PropertySetTest.java

+ 2
- 0
WHATSNEW View File

@@ -234,6 +234,8 @@ Fixed bugs:
* <unzip> and <untar> could leave file handles open on invalid
archives. Bugzilla report 34893.

* propertyset threw NPE with nested, mapped propertysets.

Other changes:
--------------



+ 39
- 0
src/etc/testcases/types/propertyset.xml View File

@@ -52,4 +52,43 @@
exp="barB=BarB, fooA=FooA"
got="${toString:my-set}"/>
</target>

<target name="nested-mapped">
<propertyset id="nested-mapped">
<propertyset>
<propertyset refid="properties-starting-with-foo"/>
<globmapper from="foo*" to="boo*" />
</propertyset>
<propertyset>
<propertyset refid="properties-starting-with-bar"/>
<globmapper from="bar*" to="far*" />
</propertyset>
</propertyset>
<expect.equals
test="nested mapped propertysets"
exp="booA=FooA, farB=BarB"
got="${toString:nested-mapped}"/>
</target>

<target name="nested-mapped-mapped">
<propertyset id="nested-mapped-mapped">
<propertyset>
<propertyset refid="properties-starting-with-foo"/>
<globmapper from="foo*" to="boo*" />
</propertyset>
<propertyset>
<propertyset refid="properties-starting-with-bar"/>
<globmapper from="bar*" to="far*" />
</propertyset>
<mapper>
<globmapper from="boo*" to="hoo*" />
<globmapper from="far*" to="near*" />
</mapper>
</propertyset>
<expect.equals
test="nested mapped propertysets"
exp="hooA=FooA, nearB=BarB"
got="${toString:nested-mapped-mapped}"/>
</target>

</project>

+ 8
- 14
src/main/org/apache/tools/ant/types/PropertySet.java View File

@@ -282,6 +282,12 @@ public class PropertySet extends DataType {
Hashtable props =
prj == null ? getAllSystemProperties() : prj.getProperties();

//quick & dirty, to make nested mapped p-sets work:
for (Enumeration e = setRefs.elements(); e.hasMoreElements();) {
PropertySet set = (PropertySet) e.nextElement();
props.putAll(set.getProperties());
}

if (getDynamic() || cachedNames == null) {
names = new HashSet();
addPropertyNames(names, props);
@@ -382,20 +388,7 @@ public class PropertySet extends DataType {
* @return the referenced PropertySet.
*/
protected PropertySet getRef() {
if (!isChecked()) {
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, getProject());
}

Object o = getRefid().getReferencedObject(getProject());
if (!(o instanceof PropertySet)) {
String msg = getRefid().getRefId()
+ " doesn\'t denote a propertyset";
throw new BuildException(msg);
} else {
return (PropertySet) o;
}
return (PropertySet) getCheckedRef(PropertySet.class, "propertyset");
}

/**
@@ -469,4 +462,5 @@ public class PropertySet extends DataType {
}
return b.toString();
}

}

+ 8
- 0
src/testcases/org/apache/tools/ant/types/PropertySetTest.java View File

@@ -36,4 +36,12 @@ public class PropertySetTest extends BuildFileTest {
public void testReferenceToTwoReferences() {
executeTarget("reference-to-two-references");
}

public void testNestedMapped() {
executeTarget("nested-mapped");
}

public void testNestedMappedMapped() {
executeTarget("nested-mapped-mapped");
}
}

Loading…
Cancel
Save