diff --git a/src/main/org/apache/tools/ant/Location.java b/src/main/org/apache/tools/ant/Location.java index 076ee0075..3a9d8114c 100644 --- a/src/main/org/apache/tools/ant/Location.java +++ b/src/main/org/apache/tools/ant/Location.java @@ -55,6 +55,7 @@ package org.apache.tools.ant; import java.io.Serializable; +import org.xml.sax.Locator; /** * Stores the location of a piece of text within a file (file name, @@ -92,6 +93,18 @@ public class Location implements Serializable { this(fileName, 0, 0); } + /** + * Creates a location from the SAX locator using the system ID as + * the filename. + * + * @param locator Must not be null. + * + * @since Ant 1.6 + */ + public Location(Locator loc) { + this(loc.getSystemId(), loc.getLineNumber(), loc.getColumnNumber()); + } + /** * Creates a location consisting of a file name, line number and * column number. diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java index 9bd909c58..738a05851 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java @@ -578,7 +578,8 @@ public class ProjectHelperImpl extends ProjectHelper { name = value; if (name.equals("")) { throw new BuildException("name attribute must not" - + " be empty"); + + " be empty", + new Location(helperImpl.locator)); } } else if (key.equals("depends")) { depends = value; @@ -783,8 +784,7 @@ public class ProjectHelperImpl extends ProjectHelper { task.setTaskName(tag); } - task.setLocation(new Location(helperImpl.locator.getSystemId(), helperImpl.locator.getLineNumber(), - helperImpl.locator.getColumnNumber())); + task.setLocation(new Location(helperImpl.locator)); helperImpl.configureId(task, attrs); task.setOwningTarget(target);