Browse Source

Fix for NPE reported by Nick Chalko.

When overriding a definition the code did not
check if the old (or new) definitions classes existed


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274876 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 22 years ago
parent
commit
facb8658b2
3 changed files with 42 additions and 2 deletions
  1. +7
    -0
      src/etc/testcases/taskdefs/typedef.xml
  2. +28
    -2
      src/main/org/apache/tools/ant/ComponentHelper.java
  3. +7
    -0
      src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java

+ 7
- 0
src/etc/testcases/taskdefs/typedef.xml View File

@@ -46,4 +46,11 @@
<local id="local" />
</target>

<target name="double-notpresent">
<typedef name="mytask" classname="notpresent" onerror="ignore"/>
<typedef name="mytask" classname="notpresent" onerror="ignore"/>
<typedef name="mytask" classname="org.apache.tools.ant.taskdefs.Echo"
onerror="ignore"/>
<mytask>hi</mytask>
</target>
</project>

+ 28
- 2
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -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()) {


+ 7
- 0
src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java View File

@@ -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");
}
}

Loading…
Cancel
Save