Bug 31215 - same macrodef causes "Trying to override task definition"
Summary: same macrodef causes "Trying to override task definition"
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.6.2
Hardware: All All
: P3 minor (vote)
Target Milestone: 1.6.3
Assignee: Ant Notifications List
Depends on:
Reported: 2004-09-14 11:05 UTC by David Konecny
Modified: 2008-02-22 12:18 UTC (History)
1 user (show)

zip file with Ant scripts (1.07 KB, application/octet-stream)
2004-09-14 11:07 UTC, David Konecny
possible patch of the problem (4.43 KB, patch)
2004-09-14 11:09 UTC, David Konecny
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Konecny 2004-09-14 11:05:05 UTC
"Trying to override task definition" is logged as MSG_WARN instead of
MSG_VERBOSE in my usage of <macrodef> task. I will attach simple scripts which
demonstrate the issue. There are three files:
* template.xml defines two macros: <myecho> and <myecho2>. The only difference
is that <myecho2> has attribute with default value (important for the case
* subproject.xml imports template.xml and uses both macros
* mainproject.xml imports template.xml and uses both macros and in addition
calls also subproject.xml

If you execute mainproject.xml you will get warning "Trying to override old
definition of task http://www.netbeans.org/ns/myecho/2:myecho2" but I think it
should be logged as MSG_VERBOSE only.

Looking at the source code of ComponentHelper.updateDataTypeDefinition() it
first checks whether AntTypeDefinitions are sameDefinition(). <myecho> is the
same, but <myecho2> is not because its value of default attribute is different -
see the scripts. What follows is that similarDefinition() is called on
AntTypeDefinitions. I know nothing about what is your semantics of "similar",
but common sense told me that they should be similar because it is the same
macro. :-) But this methods returns false too which results in MSG_WARN logging
level to be used.

I played with that a bit more and will attach also possible patch which solved
the issue for me. I changed two things:
* MacroDef.MyAntTypeDefinition.similarDefinition used to be the same as
MacroDef.MyAntTypeDefinition.sameDefinition. Now it is less strict and ignore
default value of macro attributes, but as I said I have no idea what is the
semantics of similarity.
* AntTypeDefinition.similarDefinition was returning false to me because my
classloader is URLClassLoader and not AntClassLoader as expected now. Even less
clear to me what is wrong here.

Btw. it is issue <http://www.netbeans.org/issues/show_bug.cgi?id=43968> for
NetBeans IDE which now uses Ant as native build system. It is not high priority,
just more clutter in output and "a bug" for some of our users.
Comment 1 David Konecny 2004-09-14 11:07:23 UTC
Created attachment 12727 [details]
zip file with Ant scripts
Comment 2 David Konecny 2004-09-14 11:09:47 UTC
Created attachment 12728 [details]
possible patch of the problem
Comment 3 Peter Reilly 2004-09-14 17:54:32 UTC
First thanks for the clear report!

The two myecho2 macros are different - they do have different behaviour
when <myecho2/> is used. As you point out, this is due to the different
setting of the defaulted attribute.

The similar/same issue came for attempting to deal with:
<project default="call">
   <taskdef name="x" classname="y" classpath="z"/>
   <target name="call">
      <antcall target="callee"/>
   <target name="callee">

This is a common use-case, and we do not want to get a
message that "x" has been redefined. The second definition
is not exactly the same as the first - it may have a different
classloader, hence the similar method and the VERBOSE message.

If someone did:

   <taskdef name="x" classname="y"/>
   <taskdef name="x" classname="anotherclass"/>

We want to tell the user that x has been redefined. {Although
there are bug reports about this been too noisey}.

The same idea carries over to macrodef (and the other *def)

The issue with AntTypeDefinition.similarDefinition not checking
to see if the classloaders are the same is a bug - thanks.

So the question is, should ant report the differences between
the two definitions of <myecho2> ?

I see a number of solutions:

1) treat differences in default values as "similar" - your patch
2) treat all redefinitions as VERBOSE
3) leave as is

As this is important from the point of view of intergration
with netbeans, I would be inclined to option 1) or option 2).
However, I would like other comments before committing the patch.
Comment 4 David Konecny 2004-09-23 10:07:32 UTC
Thanks for the explanation.

Re. "from the point of view of intergration with netbeans" - I just worked
around it in NetBeans by filtering these messages out from output which user can
see in IDE.
Comment 5 Peter Reilly 2005-03-15 14:24:53 UTC
Changed summary to reflect the fact that it is the
same macrodef definition that causes the problem
Comment 6 Peter Reilly 2005-03-15 14:38:45 UTC
The ant code now allows macrodefs declared in the same
file/line to be treated as similar definitions, and so
the log mesage will be VERBOSE.