Bug 49162 - incorrect duplicated project name warning when imports from URL-providing resource
Summary: incorrect duplicated project name warning when imports from URL-providing res...
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.8.1
Hardware: All All
: P2 normal (vote)
Target Milestone: 1.8.1
Assignee: Ant Notifications List
Depends on:
Reported: 2010-04-21 06:14 UTC by Sky Ao
Modified: 2010-05-09 07:37 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Sky Ao 2010-04-21 06:14:59 UTC
I'am interesting in the new feature comes from ant 1.8.0:

"<import> can now import from any file- or URL-providing resource - this includes <javaresource>."

Yesteday I had a try to import URL-providing ant xml file, I had some ant build files like this :

-root of product
    - commom/
        + common.xml
        + ivy.xml
        + publish.xml
    - project1
        + build.xml
    - project2
        + build.xml

The build.xml files in project1/2/3/4... import the common.xml file, and common.xml file imports all other xml files in common directory. This is very common for multiple projects to share the common build targets.

These ant build file work well when I use normal file import. But when I move common directory and all the ant xml file to a jar and then in project1/2/3/4... import this common.xml as URL-providing resource. These ant builf file work well except a warnning in ant log:

"Duplicated project name in import. Project *** defined first in **** and again in null"

I'm sure that all the project name are not Duplicated.

And this warning will only appear in this specifical case: using <buildlist> to get a build files list of project1/2/3/4...  and then execute the target in each build file. If only one project's build.xml, this warning would not happen.

I have download the source code of ant 1.8 and found the reason of this warning:

1. in org.apache.tools.ant.helper.ProjectHelper2

                if (context.isIgnoringProjectTag() && !dupFile.equals(context.getBuildFile())) {
                    project.log("Duplicated project name in import. Project "
                            + context.getCurrentProjectName() + " defined first in " + dup
                            + " and again in " + context.getBuildFile(), Project.MSG_WARN);

    Compare to the warning log "and again in null", we can know that  context.getBuildFile() would return null. In this case, !dupFile.equals(context.getBuildFile()) would always return true and cause the incorrect warning.

2. in org.apache.tools.ant.helper.AntXMLContext

    public void setBuildFile(File buildFile) {
        this.buildFile = buildFile;

     * @since Ant 1.8.0
    public void setBuildFile(URL buildFile) throws MalformedURLException {
        this.buildFileURL = buildFile;

    public File getBuildFile() {
        return buildFile;

    Now we can see that if we use URL import, the setBuildFile(URL buildFile) method will be invoked but it will set attibute buildFileURL, not attibute  buildFile, so the method getBuildFile() will always return null.

    I think this would be a bug, the check logic for duplicated project name would be updated for the new fearture URL-providing import added in ant 1.8.
Comment 1 Stefan Bodewig 2010-04-22 07:18:52 UTC
I think this is fixed now by svn revision 936784 but I'm having a hard time creating a test case.

Could you try to build Ant from svn and see whether the problem is really fixed?
Comment 2 Stefan Bodewig 2010-05-04 08:14:30 UTC
1.8.1 is about to be released soon.  In fact the archives that will make up
the release are currently voted on and can be found at

It would be great if you could give it a try before we announce the final
release - we may be able to delay the release if the problem still persists.
Comment 3 Sky Ao 2010-05-09 07:36:24 UTC
I have verified this bug with new version 1.8.1, this warning doesn't appear now.

Also I have checked the source code of class org.apache.tools.ant.helper ProjectHelper2, the code above in my bug report has been updated to add check for both context.getBuildFileURL() and context.getBuildFile():

if (MagicNames.ANT_FILE_TYPE_URL.equals(dupType)) {
    contextFile = context.getBuildFileURL();
} else {
    contextFile = context.getBuildFile();

if (context.isIgnoringProjectTag() && !dupFile.equals(contextFile)) {
    project.log("Duplicated project name in import. Project "
       + context.getCurrentProjectName() + " defined first in " + dup
       + " and again in " + contextFile, Project.MSG_WARN);

I think this bug has been fix and this issue would be closed.

Thanks to all.