Browse Source

typedef: check for recursive loading of xml files/resources (aka antlibs)

typedef: do not throw an NPE if attempting to load a file that does not exist


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276492 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
fa7d0ce02c
1 changed files with 26 additions and 1 deletions
  1. +26
    -1
      src/main/org/apache/tools/ant/taskdefs/Definer.java

+ 26
- 1
src/main/org/apache/tools/ant/taskdefs/Definer.java View File

@@ -21,7 +21,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.Properties;
@@ -41,6 +43,15 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* @since Ant 1.4
*/
public abstract class Definer extends DefBase {
private static class ResourceStack extends ThreadLocal {
public Object initialValue() {
return new ArrayList();
}
List getStack() {
return (List) get();
}
}
private static ResourceStack resourceStack = new ResourceStack();
private String name;
private String classname;
private File file;
@@ -179,6 +190,9 @@ public abstract class Definer extends DefBase {
Enumeration/*<URL>*/ urls = null;
if (file != null) {
final URL url = fileToURL();
if (url == null) {
return;
}
urls = new Enumeration() {
private boolean more = true;
public boolean hasMoreElements() {
@@ -209,7 +223,18 @@ public abstract class Definer extends DefBase {
loadProperties(al, url);
break;
} else {
loadAntlib(al, url);
if (resourceStack.getStack().contains(url)) {
log("Warning: Attempting to recursively load " + url
+ " at " + getLocation(),
Project.MSG_WARN);
} else {
try {
resourceStack.getStack().add(url);
loadAntlib(al, url);
} finally {
resourceStack.getStack().remove(url);
}
}
}
}
}


Loading…
Cancel
Save