Bug 50007 - Taskdef classpath breaks with directory containing an exclamation mark (!)
Summary: Taskdef classpath breaks with directory containing an exclamation mark (!)
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.8.2
Hardware: PC All
: P2 regression (vote)
Target Milestone: ---
Assignee: Ant Notifications List
Depends on:
Reported: 2010-09-27 00:47 UTC by Trejkaz (pen name)
Modified: 2021-01-23 11:25 UTC (History)
0 users

test build (200.16 KB, application/zip)
2010-09-27 00:47 UTC, Trejkaz (pen name)

Note You need to log in before you can comment on or make changes to this bug.
Description Trejkaz (pen name) 2010-09-27 00:47:11 UTC
Created attachment 26078 [details]
test build

We discovered an issue when a project directory containing a "!" was used with Ant upgraded to version 1.8.1.

My initial hunch is that Ant is converting this file path to a URI and then the ! is being misinterpreted as a separator for the jar URL scheme, even though "jar:" was nowhere to be seen.  As the variable in question comes from one of Ant's own tasks, one would expect it to work when used as part of the parameter for another task, and indeed, the issue does not occur on version 1.7.0.

I zipped up a minimal build directory which reproduces the issue, at least on Windows.

Buildfile: G:\!test\build.xml

G:\!test\build.xml:3: The following error occurred while executing this line:
java.io.FileNotFoundException: G:\ (The filename, directory name, or volume label syntax is incorrect)
        at java.io.RandomAccessFile.open(Native Method)
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
        at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:182)
        at org.apache.tools.zip.ZipFile.<init>(ZipFile.java:148)
        at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:274)
        at org.apache.tools.ant.helper.ProjectHelper2.parseUnknownElement(ProjectHelper2.java:130)
        at org.apache.tools.ant.helper.ProjectHelper2.parseAntlibDescriptor(ProjectHelper2.java:110)
        at org.apache.tools.ant.taskdefs.Antlib.createAntlib(Antlib.java:91)
        at org.apache.tools.ant.taskdefs.Definer.loadAntlib(Definer.java:440)
        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: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:390)
        at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:179)
        at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:82)
        at org.apache.tools.ant.Main.runBuild(Main.java:786)
        at org.apache.tools.ant.Main.startAnt(Main.java:218)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

Total time: 0 seconds
Comment 1 Stefan Bodewig 2010-09-27 09:01:47 UTC
Well, there is a jar: protocol in view.  The error you see is when Ant
tries to read the antlib.xml from ant-contrib.jar and its URL will
be something like

Using lastIndexOf("!") instead of indexOf("!") would help in this case but I
need to think through the possible code paths first to convince myself that
no "!" could ever appear after the ! inside the JAR protocol.
Comment 2 Stefan Bodewig 2010-09-27 10:35:25 UTC
svn revision 1001756 fixes this as long as the ! is not at the end of the
directory name.  In the later case JarURLConnection.connect() fails for an
URL returned by Classloader.getResources() - I'm not convinced there
is anything we can do for this case, but I'm keeping the issue open in case
anybody has a good idea.
Comment 3 Trejkaz (pen name) 2010-09-27 19:19:53 UTC
Aha, the hidden JAR URL. :)
There is some talk of this on a Sun bug record too.

The suggestion someone gives there is only to match the ! if it's actually after .jar so that it won't match a bare directory.  I guess it won't match .zip which could technically contain classes too, but IMO it's not a jar file unless it ends in .jar anyway, so it would seem like it would just encourage people not to do things in a strange way.

What perplexes me is that Ant 1.7.0 didn't have the issue.  I am guessing it wasn't using URLs?