Browse Source

If someone tries to append a path to itself, choke gracefully, not with a StackOverflowError.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@470125 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 18 years ago
parent
commit
98d1226139
2 changed files with 14 additions and 1 deletions
  1. +3
    -1
      src/main/org/apache/tools/ant/types/Path.java
  2. +11
    -0
      src/tests/junit/org/apache/tools/ant/types/PathTest.java

+ 3
- 1
src/main/org/apache/tools/ant/types/Path.java View File

@@ -19,7 +19,6 @@
package org.apache.tools.ant.types;

import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
@@ -238,6 +237,9 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* @since Ant 1.6
*/
public void add(Path path) throws BuildException {
if (path == this) {
throw circularReference();
}
if (path.getProject() == null) {
path.setProject(getProject());
}


+ 11
- 0
src/tests/junit/org/apache/tools/ant/types/PathTest.java View File

@@ -549,4 +549,15 @@ public class PathTest extends TestCase {
assertEquals(project.resolveFile("build").getAbsolutePath(), l[0]);
}

public void testRecursion() {
Path p = new Path(project);
try {
p.append(p);
assertEquals(0, p.list().length);
} catch (BuildException x) {
String m = x.toString();
assertTrue(m, m.indexOf("circular") != -1);
}
}

}

Loading…
Cancel
Save