diff --git a/src/etc/testcases/taskdefs/typedef.xml b/src/etc/testcases/taskdefs/typedef.xml
index 165d4df93..39635f876 100644
--- a/src/etc/testcases/taskdefs/typedef.xml
+++ b/src/etc/testcases/taskdefs/typedef.xml
@@ -46,4 +46,11 @@
+
+
+
+
+ hi
+
\ No newline at end of file
diff --git a/src/main/org/apache/tools/ant/ComponentHelper.java b/src/main/org/apache/tools/ant/ComponentHelper.java
index 010b9cc6b..a8032e1a2 100644
--- a/src/main/org/apache/tools/ant/ComponentHelper.java
+++ b/src/main/org/apache/tools/ant/ComponentHelper.java
@@ -587,9 +587,33 @@ public class ComponentHelper {
}
- /** return true if the two definitions are the same */
+ /**
+ * check if definition is a valid definition - it
+ * may be a definition of an optional task that
+ * does not exist
+ * @param def the definition to test
+ * @return true if exposed type of definition is present
+ */
+ private boolean validDefinition(AntTypeDefinition def) {
+ if (def.getTypeClass(project) == null
+ || def.getExposedClass(project) == null) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * check if two definitions are the same
+ * @param def the new definition
+ * @param old the old definition
+ * @return true if the two definitions are the same
+ */
private boolean sameDefinition(
AntTypeDefinition def, AntTypeDefinition old) {
+ if (!validDefinition(def) || !validDefinition(old)) {
+ return validDefinition(def) == validDefinition(old);
+ }
+
if (!(old.getTypeClass(project).equals(def.getTypeClass(project)))) {
return false;
}
@@ -600,9 +624,11 @@ public class ComponentHelper {
return true;
}
+
/**
* update the component definition table with a new or
* modified definition.
+ * @param def the definition to update or insert
*/
private void updateDataTypeDefinition(AntTypeDefinition def) {
String name = def.getName();
@@ -615,7 +641,7 @@ public class ComponentHelper {
return;
}
Class oldClass = antTypeTable.getExposedClass(name);
- if (Task.class.isAssignableFrom(oldClass)) {
+ if (oldClass != null && Task.class.isAssignableFrom(oldClass)) {
int logLevel = Project.MSG_WARN;
if (def.getClassName().equals(old.getClassName())
&& def.getClassLoader() == old.getClassLoader()) {
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java b/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java
index 17e09c373..22f3b04a0 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java
@@ -104,4 +104,11 @@ public class TypedefTest extends BuildFileTest {
ref.getClass().getName());
}
+ /**
+ * test to make sure that one can define a not present
+ * optional type twice and then have a valid definition.
+ */
+ public void testDoubleNotPresent() {
+ expectLogContaining("double-notpresent", "hi");
+ }
}