Bug 48980 - complete-ant-cmd.pl can cache empty completion list if ant fails with OOM
Summary: complete-ant-cmd.pl can cache empty completion list if ant fails with OOM
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.7.1
Hardware: All Mac OS X 10.4
: P2 minor (vote)
Target Milestone: 1.8.1
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2010-03-24 20:37 UTC by Omer Shapira
Modified: 2010-03-25 14:15 UTC (History)
1 user (show)



Attachments
Proposed patch to the bug (610 bytes, patch)
2010-03-24 20:45 UTC, Omer Shapira
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Omer Shapira 2010-03-24 20:37:16 UTC
complete-ant-cmd.pl is a helper script which allows BASH and KSH users to complete ant targets using shell completion facility.

It works by calling ant -p to get list of possible targets, and caching the result. The cached result is stored in working directory, in file ".ant-targets-XXX.xml" (XXX stands for the build file name)

Unfortunately, if ant -p fails (e.g. with OOM exception), empty completion list is cached for the directory.

Once this happens, the completion stops working.


Steps to reproduce (bash):

1. Associate complete-ant-cmd.pl with the bash completion facility:

     complete -C $ANT_HOME/bin/complete-ant-cmd.pl ant
 
2. create build file build.xml, containing the following input:

   <project name="test">
      <target name="test"/>
   </project>

2. verify that ant completion works 
   type ant and hit TAB (assuming TAB is the completion key)
   
   Expected result: the command line should be completed to 
   
   $ ant test

3. Delete file ./.ant-targets-build.xml
 
4. Simulate exception in ant. One way to do so would be setting ANT_HOME to wrong location: 
   export ANT_HOME=/tmp

5. type ant and hit TAB 
   Expected result: ant Exception in thread "main" 
   java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher

   Expected result - 0 sized file called ./.ant-targets-build.xml will be created.

6. restore ANT_HOME to original value 

7. type ant and hit TAB 

Completion will not work.
Comment 1 Omer Shapira 2010-03-24 20:45:07 UTC
Created attachment 25179 [details]
Proposed patch to the bug

The proposed patch checks if the cache file exists, but is empty. 

In this case, the completion script proceeds to regenerating the cache file.
Comment 2 Stefan Bodewig 2010-03-25 14:02:59 UTC
Omar, please don't assign the bug to yourself or the Ant developers won't see any changes.
Comment 3 Stefan Bodewig 2010-03-25 14:04:18 UTC
I'm sorry I misspelled your name, will look into your patch shortly.
Comment 4 Stefan Bodewig 2010-03-25 14:15:06 UTC
patch is in svn revision 927416

Thanks!