Bug 46747 - sync task crashes with NPE when trying to delete dead directory symlink
Summary: sync task crashes with NPE when trying to delete dead directory symlink
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.7.1
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: 1.8.0
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-20 08:02 UTC by skoppehel
Modified: 2009-02-23 05:14 UTC (History)
0 users



Attachments
Patch to test for null (616 bytes, patch)
2009-02-22 05:36 UTC, skoppehel
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description skoppehel 2009-02-20 08:02:07 UTC
I've only tested this on Linux, I assume it is the same on all Unix-like operating systems that support symlinks. Suppose you have in a directory a subdirectory and a symbolic link to it. Then you try, via ant, to sync another directory to it that contains neither. The sync task will try to delete both, and will fail.

To set up a test case, do:

    mkdir t s t/n
    ln -s n t/m

and then execute the following ant target:

    <target name="synchro">
        <sync todir="t">
            <fileset dir="s">
                <include name="**/*" />
            </fileset>
        </sync>
    </target>

What will happen is this:

Buildfile: build.xml

synchro:

BUILD FAILED
java.lang.NullPointerException
        at org.apache.tools.ant.taskdefs.Sync.removeOrphanFiles(Sync.java:218)
        at org.apache.tools.ant.taskdefs.Sync.execute(Sync.java:118)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
        at org.apache.tools.ant.Main.runBuild(Main.java:758)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

Total time: 0 seconds
Comment 1 skoppehel 2009-02-22 05:36:56 UTC
Created attachment 23295 [details]
Patch to test for null

The attached patch makes the NPE go away by testing f.list() for null before looking at length. Whether or not the fact that a non-listable file appears at this point is indicative of a deeper bug somewhere else, I cannot say. The test case I described now works as expected, the dead link gets deleted.
Comment 2 Stefan Bodewig 2009-02-23 05:14:44 UTC
patch applied as svn revision 747004

Thanks!