diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index b5cc076d8..ced380cab 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -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()); } diff --git a/src/tests/junit/org/apache/tools/ant/types/PathTest.java b/src/tests/junit/org/apache/tools/ant/types/PathTest.java index 25fd99349..f3b6b3979 100644 --- a/src/tests/junit/org/apache/tools/ant/types/PathTest.java +++ b/src/tests/junit/org/apache/tools/ant/types/PathTest.java @@ -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); + } + } + }