Bug 54473

Summary: taskdef can't find existing resource in jar file on the first try, but on the second - JarUrlConnection.connect() fails
Product: Ant Reporter: René Krell <renda.krell>
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: REOPENED ---    
Severity: normal CC: renda.krell
Priority: P2    
Version: 1.9.1   
Target Milestone: 1.9.4   
Hardware: PC   
OS: Linux   
Attachments: patch for ProjectHelper2
Patch for the ANT_18_BRANCH

Description René Krell 2013-01-23 11:53:07 UTC
In rare cases, but reproducable on certain testsystems, I get the following stacktrace:

com.izforge.izpack.installer.InstallerException: The following error occurred while executing this line:
/tmp/buildfile_resource7846034884221422628xml:7: The following error occurred while executing this line:
/usr/local/app/bin/database_contents.xml:5: The following error occurred while executing this line:
Unable to find jar:file:/usr/local/app/lib/ant/ant-contrib/1.0b3/ant-contrib.jar!/net/sf/antcontrib/antlib.xml
        at com.izforge.izpack.event.AntActionInstallerListener.performAllActions(Unknown Source)
        at com.izforge.izpack.event.AntActionInstallerListener.afterPacks(Unknown Source)
        at com.izforge.izpack.installer.UnpackerBase.informListeners(Unknown Source)
        at com.izforge.izpack.installer.Unpacker.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:736)
Caused by: The following error occurred while executing this line:
/tmp/buildfile_resource7846034884221422628xml:7: The following error occurred while executing this line:
/usr/local/app/bin/database_contents.xml:5: The following error occurred while executing this line:
Unable to find jar:file:/usr/local/app/lib/ant/ant-contrib/1.0b3/ant-contrib.jar!/net/sf/antcontrib/antlib.xml
        at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:551)
        at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:395)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:600)
        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:392)
        at org.apache.tools.ant.Target.performTasks(Target.java:413)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
        at com.izforge.izpack.event.AntAction.performAction(Unknown Source)
        at com.izforge.izpack.event.AntAction.performInstallAction(Unknown Source)
        ... 5 more
Caused by: /tmp/buildfile_resource7846034884221422628xml:7: The following error occurred while executing this line:
/usr/local/app/bin/database_contents.xml:5: The following error occurred while executing this line:
Unable to find jar:file:/usr/local/app/lib/ant/ant-contrib/1.0b3/ant-contrib.jar!/net/sf/antcontrib/antlib.xml
        at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:551)
        at org.apache.tools.ant.taskdefs.ImportTask.importResource(ImportTask.java:238)
        at org.apache.tools.ant.taskdefs.ImportTask.execute(ImportTask.java:163)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:600)
        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:392)
        at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:180)
        at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:82)
        at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:393)
        ... 17 more
Caused by: /usr/local/app/bin/database_contents.xml:5: The following error occurred while executing this 
line:
Unable to find jar:file:/usr/local/app/lib/ant/ant-contrib/1.0b3/ant-contrib.jar!/net/sf/antcontrib/antlib.xml
        at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:551)
        at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:445)
        at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:292)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:600)
        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:392)
        at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:169)
        at org.apache.tools.ant.taskdefs.ImportTask.importResource(ImportTask.java:229)
        ... 29 more
Caused by: Unable to find jar:file:/usr/local/app/lib/ant/ant-contrib/1.0b3/ant-contrib.jar!/net/sf/antcontrib/antlib.xml
        at org.apache.tools.ant.taskdefs.Antlib.createAntlib(Antlib.java:68)
        at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:440)
        ... 40 more
Caused by: java.io.FileNotFoundException: JAR entry net/sf/antcontrib/antlib.xml not found in /usr/local/app/lib/ant/ant-contrib/1.0b3/ant-contrib.jar
        at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:125)
        at org.apache.tools.ant.taskdefs.Antlib.createAntlib(Antlib.java:66)
        ... 41 more


in the definition:
  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <pathelement location="${install.prefix}/lib/ant/ant-contrib/1.0b3/ant-contrib.jar"/>
    </classpath>
  </taskdef>

The File and the resource in it definitely exist.
Ant 1.8.4 is used built-in here from an Izpack installer, but this doesn't play any role here, IMHO.

The important point is, that it fails just on the first try, but on the second on it suceeds, although there hasn't been changed anything on the appropriate location in between time.

Note:
At the links
- https://jira.springsource.org/browse/SPR-4639
- http://stackoverflow.com/questions/1374438/disappearing-jar-entry-when-loading-using-spi
I found some discussion about switching off caching in such cases for UrlConnection. Maybe this could be useful also for Ant.
Comment 1 René Krell 2013-01-23 11:56:32 UTC
OS, where this bug occurs:
Linux 2.6.32.12-0.7-default #1 SMP 2010-05-20 11:14:20 +0200 x86_64 x86_64 x86_64 GNU/Linux
Comment 2 René Krell 2013-01-23 11:58:24 UTC
JRE, which this bug occurs with:
- Oracle JRE 6u38, Linux 64 bit
- IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux amd64-64 jvmxa6460sr7-20091214_49398 (JIT enabled, AOT enabled)
Comment 3 Antoine Levy-Lambert 2013-01-24 04:33:25 UTC
Created attachment 29888 [details]
patch for ProjectHelper2

suggested patch based on the information in the bug report
Comment 4 René Krell 2013-01-24 06:48:15 UTC
Created attachment 29889 [details]
Patch for the ANT_18_BRANCH

Here is another patch for the Ant 1.8 branch which solves the problem for me. Are you able to apply this? Thanks
Comment 5 Stefan Bodewig 2014-01-01 21:56:02 UTC
I've combined both patches and also fixed some other places that looked suspicious.

svn revision 1554684
Comment 6 Stefan Bodewig 2014-01-02 16:06:30 UTC
amended with revision 1554840
Comment 7 René Krell 2014-03-27 16:37:48 UTC
Would appreciate a release with this fix, this still occurs in 1.9.3 for me.
Comment 8 Antoine Levy-Lambert 2014-03-30 23:42:42 UTC
let's discuss a schedule for the next release on the user list
Comment 9 René Krell 2014-04-30 08:47:39 UTC
Unfortunately I got the reopen this for the following reason:
The most latest suggested patch didn't apply for me, the problem reoccurred. The is necessary to apply this patch for solving it: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Antlib.java?r1=1375571&r2=1554684&pathrev=1554840
Thus, using conn.setDefaultUseCaches(false), not just setUseCaches(false), for whatever reason.