peterreilly 2003/07/21 03:10:07 Modified: src/main/org/apache/tools/ant ComponentHelper.java src/etc/testcases/taskdefs typedef.xml src/testcases/org/apache/tools/ant/taskdefs TypedefTest.java Log: Fix for NPE reported by Nick Chalko. When overriding a definition the code did not check if the old (or new) definitions classes existed Revision Changes Path 1.19 +28 -2 ant/src/main/org/apache/tools/ant/ComponentHelper.java Index: ComponentHelper.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ComponentHelper.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- ComponentHelper.java 6 Jul 2003 09:57:34 -0000 1.18 +++ ComponentHelper.java 21 Jul 2003 10:10:06 -0000 1.19 @@ -587,9 +587,33 @@ } - /** 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 @@ 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 @@ 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()) { 1.2 +7 -0 ant/src/etc/testcases/taskdefs/typedef.xml Index: typedef.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/typedef.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- typedef.xml 9 Nov 2001 15:48:11 -0000 1.1 +++ typedef.xml 21 Jul 2003 10:10:06 -0000 1.2 @@ -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> 1.6 +8 -1 ant/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java Index: TypedefTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/TypedefTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TypedefTest.java 7 Mar 2003 11:23:11 -0000 1.5 +++ TypedefTest.java 21 Jul 2003 10:10:07 -0000 1.6 @@ -104,4 +104,11 @@ 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"); + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]