Bug 42275 - running ant off a network share can cause Ant to fail
Summary: running ant off a network share can cause Ant to fail
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.7.0
Hardware: Other Windows XP
: P2 normal (vote)
Target Milestone: 1.8.0
Assignee: Ant Notifications List
URL:
Keywords:
: 42422 45846 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-04-27 04:41 UTC by Steve Loughran
Modified: 2008-11-06 19:17 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Loughran 2007-04-27 04:41:45 UTC
This is from Ant User...someone is running ant in their own bat file, with a
classpath containing entries like 
 \\PC03\jclasses\lib\ant-1.7.0.jar
on the classpath.

Ant is failing while trying to create the URI of the file
java.lang.IllegalArgumentException: URI has an authority component
       at java.io.File.<init>(Unknown Source)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
       at java.lang.reflect.Constructor.newInstance(Unknown Source)
       at org.apache.tools.ant.launch.Locator.fromURI(Locator.java:165)
       at org.apache.tools.ant.launch.Locator.getResourceSource(Locator.java:119)
       at org.apache.tools.ant.launch.Locator.getClassSource(Locator.java:90)
       at org.apache.tools.ant.Project.setAntLib(Project.java:313)
       at org.apache.tools.ant.Project.initProperties(Project.java:309)
       at org.apache.tools.ant.Project.init(Project.java:295)
       at org.apache.tools.ant.Main.runBuild(Main.java:663)
       at org.apache.tools.ant.Main.startAnt(Main.java:199)
       at org.apache.tools.ant.Main.start(Main.java:161)
       at org.apache.tools.ant.Main.main(Main.java:250)
Comment 1 Steve Loughran 2007-04-27 05:43:11 UTC
This is related to Java bug
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086147

new File(file1.toURI().toString()) fails if file1 is a network file.

this is seemingly fixed in Java1.6, though I can still get our (new) test to
fail on java1.6
Comment 2 Steve Loughran 2007-05-15 05:10:57 UTC
*** Bug 42422 has been marked as a duplicate of this bug. ***
Comment 3 Steve Loughran 2007-05-22 13:44:54 UTC
Believe this is fixed in Ant1.7.1; re-open if this is not the case.
Comment 4 Ron Saito 2008-02-14 13:34:50 UTC
doing \\somesystem\ant\bin\ant -version 
-using 2/14/08 nightly (1.8.0alpha)

java.lang.ClassNotFoundException: org.apache.tools.ant.Main
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:255)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Comment 5 Steve Loughran 2008-02-18 03:09:01 UTC
...yes, I can confirm this too.

C:\Documents and Settings\slo>\\morzine\slo\Java\Apache\ant\bin\ant.bat  -version
java.lang.ClassNotFoundException: org.apache.tools.ant.Main
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:255)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

-debug, -verbose, -diagnostics options don't get a look in
Comment 6 Steve Loughran 2008-02-26 06:29:03 UTC
A bit more logging on failures and we see what is going on :

C:\>\\morzine\slo\Java\Apache\ant\bin\ant.bat
Unable to locate tools.jar. Expected to find it in C:\Java\lib\tools.jar
Failed to locateorg.apache.tools.ant.Main
ant.home\\morzine\slo\Java\Apache\ant\bin\..
Classpath: \\morzine\slo\Java\Apache\ant\bin\..\lib\ant-launcher.jar
Launcher JAR: C:\morzine\slo\Java\Apache\ant\lib\ant-launcher.jar
launcher Directory: C:\morzine\slo\Java\Apache\ant\lib
C:\>

We are failing to correctly determine the path to the launcher JAR, and hence to
ANT_HOME
Comment 7 Steve Loughran 2008-02-26 06:34:03 UTC
More logging shows that the URL is being correct
C:\>\\morzine\slo\Java\Apache\ant\bin\ant.bat
org/apache/tools/ant/launch/Launcher.class is in jar:file://morzine/slo/Java/Apa
che/ant/lib/ant-launcher.jar!/org/apache/tools/ant/launch/Launcher.class

This puts the bug in fromURIJava13
Comment 8 Steve Loughran 2008-02-26 07:56:54 UTC
Fixed in Ant1.8; leave it to kevin to see if he wants to add it to ant 1.7
Comment 9 Stefan Bodewig 2008-09-25 06:47:32 UTC
*** Bug 45846 has been marked as a duplicate of this bug. ***
Comment 10 Jesse Glick 2008-09-30 11:03:05 UTC
An apparently related bug: using a basic <import> in a project located on a UNC share works in 1.7.0 and 1.8 dev but not in 1.7.1. See

http://www.netbeans.org/nonav/issues/show_bug.cgi?id=146948

for details. SVN logs confusingly has two entries for this bug:

------------------------------------------------------------------------
r631263 | stevel | 2008-02-26 10:52:51 -0500 (Tue, 26 Feb 2008) | 1 line

Bug 42275 running ant off a network share can cause Ant to fail
------------------------------------------------------------------------
r533082 | stevel | 2007-04-27 08:45:53 -0400 (Fri, 27 Apr 2007) | 9 lines

Bug 42275: ant doesnt run from a network share, because of an error when trying to work out where we loaded from.

1. this exception is still raised, but caught and causes ant to skip setting ant.lib.

2. we now have a test class for Locator

3. I've split out the java1.3 support and made it public, so we can test it separately. 

One of the tests is failing, showing the problem is still there. We need to decide what to do about it (ignore, switch to java1.3 code...)
------------------------------------------------------------------------
Comment 11 Miles Daffin 2008-09-30 14:12:13 UTC
I fixed the import issue in 1.7.1 (as reported in Bug 45846) by using dirname to get the base path of the importing file, e.g. 

<dirname property="masterbuild.basedir" file="${ant.file.masterbuild}"/>
<import file="${masterbuild.basedir}/build-utils.xml"/>

This shows that the dirname task at least can work where things are on the file system.

HTH
Comment 12 Jesse Glick 2008-10-01 09:07:15 UTC
The minimal fix for the UNC import problem in Ant 1.7.1 (which I think should be merged to a 1.7.2 if one is created, since this is a serious regression), borrowed from SVN r631263:

Index: src/main/org/apache/tools/ant/launch/Locator.java
===================================================================
--- src/main/org/apache/tools/ant/launch/Locator.java	(revision 700534)
+++ src/main/org/apache/tools/ant/launch/Locator.java	(working copy)
@@ -275,7 +275,8 @@
             path = decodeUri(uri);
             String cwd = System.getProperty("user.dir");
             int posi = cwd.indexOf(":");
-            if ((posi > 0) && path.startsWith(File.separator)) {
+            if ((posi > 0) && path.startsWith(File.separator)
+                    /* #42275: UNC */ && !path.startsWith("\\\\")) {
                path = cwd.substring(0, posi + 1) + path;
             }
         } catch (UnsupportedEncodingException exc) {
Comment 13 Stefan Bodewig 2008-10-14 23:59:58 UTC
the fix svn revision is 42275
Comment 14 Stefan Bodewig 2008-10-15 01:23:45 UTC
sorry, 631263

http://svn.eu.apache.org/viewvc?view=rev&revision=631263
Comment 15 Jesse Glick 2008-11-06 19:17:24 UTC
FYI - for NetBeans 6.5 we are just shipping the Locator.java minipatch shown above.