Bug 10499 - Compiler task doesn't handle spaces in filenames correctly
Summary: Compiler task doesn't handle spaces in filenames correctly
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.5
Hardware: PC All
: P3 normal with 3 votes (vote)
Target Milestone: 1.6
Assignee: Ant Notifications List
URL:
Keywords:
: 17683 19285 21868 23401 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-07-05 07:13 UTC by Koen Bruyndonckx
Modified: 2005-03-20 17:06 UTC (History)
5 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Koen Bruyndonckx 2002-07-05 07:13:13 UTC
When a certain number of source files is reached, Ant generates a filelist 
which it passes to the compiler.

This filelist doesn't contain quotes around filenames which have spaces in them.

Work-around:  Make sure yourself that you use directory-names without spaces in 
them.
Comment 1 Stefan Bodewig 2002-07-05 09:27:49 UTC
It will only use the file for "external" compilers like jikes or forked javac.
Which compiler is causing problems for you?  

I'm rather sure that adding quotes around the filenames would cause jikes
(at least on Unix) to fail.
Comment 2 Koen Bruyndonckx 2002-07-05 12:13:53 UTC
We are using a forked version of javac to be sure that we are using the actual 
JDK1.1.7B version of javac.  We have a substantial number (5000+) of java 
sources written in JDK1.1.7B and aren't taking the risk of using JDK1.4.0 with 
target "1.1"

So, our build tool has to be able to support JDK1.4.0, JDK1.3 (for thin client 
development) and JDK1.1.7B.
Comment 3 Stefan Bodewig 2002-07-05 12:22:30 UTC
Hmm, are you sure you really are using JDK 1.1's javac?

According to my copy of the JDK 1.1 docs it doesn't support the @filelist
option at all.
Comment 4 Koen Bruyndonckx 2002-07-05 12:29:42 UTC
Oops,  very sorry.

The story was correct, but the problem arose with JDK1.4.0
We use fork for every version of the JDK because we need to use the extra 
settings such as MemoryInitialSize end MemoryMaxmimumSize
Comment 5 Stefan Bodewig 2002-07-05 12:37:06 UTC
Yes, and this explains a lot.  According to the docs:

> An argument file can include javac options and source filenames in any
> combination. The arguments within a file can be space-separated or
> newline-separated. 

Oh my.  So here quotes will become necessary for all platforms, I guess.

Of course it is different for JDK 1.3

> you may specify one or more files that themselves contain one filename per
> line.

Could you test whether 1.3 (or 1.2 for that matter) needs quotes for filenames
with spaces as well?  I don't have a Windows box around and suspect things
could depend on the OS.
Comment 6 Carlo Van de Sompel 2002-07-05 15:36:50 UTC
Done the test with 1.3 and 1.4 against W2K and got the same results.
Specs :
Compilation on : Microsoft Windows 2000 [Version 5.00.2195]
1. Compiled against java full version "1.4.0-b92"
error -> javac: invalid flag: C:\\ANTBUILD\\assemble\\DVL\\BA200302\\AXA ....
2. Compiled against java full version "1.3.1_01"
error -> javac: invalid argument: C:\\ANTBUILD\\assemble\\DVL\\BA200302\\AXA ...

Actual entry in the (example) source.file.list :
"C:\ANTBUILD\assemble\DVL\BA200302\AXA Bank Java 
Core\build\javaroot\be\axa\ah\service\table\RendererMetrics.java"
Both compiled correctly with the complete pathname in closing brackets.

Cheers,
Carlo

PS. next reply will be next week or tomorrow (it's already 18:00 local time)
Comment 7 Stefan Bodewig 2003-03-10 09:31:48 UTC
*** Bug 17683 has been marked as a duplicate of this bug. ***
Comment 8 Stefan Bodewig 2003-04-28 10:15:42 UTC
*** Bug 19285 has been marked as a duplicate of this bug. ***
Comment 9 Stefan Bodewig 2003-04-29 13:18:24 UTC
Should be fixed for JDK 1.4 with nightly build 2003-04-30.

We'll need some more field testing to determine which other "external" compilers
need similar treatment - I'd bet it depends on the OS as well.

Comment 10 Joe Boon 2003-06-03 14:42:26 UTC
I believe this bug is leading to problems in Tomcat, seen in bug 18595 and bug 
19725.
Comment 11 Joe Boon 2003-06-03 14:47:34 UTC
I am re-opening this bug. Based on the fix I have seen for it in a recent 1.6 
alpha nightly build it is not the correct fix.

I was hoping it would make 1.5, but it seems to have missed the last 1.5 build 
(1.5.3).

Here is the 'fix' in the 1.6 nightly build:

                    for (int i = firstFileName; i < args.length; i  ) {
                        if (quoteFiles && args[i].indexOf(" ") > -1) {
                            out.println("\""   args[i]   "\"");
                        } else {
                            out.println(args[i]);
                        }
                    }

This is not a complete fix. There are three problems with this fix:

1. It needs to escape backslashes, see bug 17683. Without doing this it will 
not work, especially on Windows which always uses backslashes.

2. The method decides whether to quote the names using the "quoteFiles" 
boolean parameter. However, there is no way of setting quoteFiles to True. 

There is no way of configuring Ant to do this. When used in Tomcat this will 
not be set. It would be great to always set this to True if running on 
Windows. At the moment, swapping ant.jar from the latest Ant 1.6 nightly-build 
into Tomcat 4.1.24 (which uses Ant 1.5.1), and restarting Tomcat does not fix 
the problem. The fix needs to work automatically.

3. The fix checks whether there is space before quoting the file. If someone 
wants to quote the file, why not always quote them. There might be other 
characters in the filename that need quoting (other white space). If it is 
going to check for spaces, then why do we need quoteFiles? Why not always 
quote files with spaces in their names?

I would be grateful if the fix could be re-done. At the moment the default 
install of Tomcat on Windows doesn't work for small to medium sized 
applications.
Comment 12 Antoine Levy-Lambert 2003-06-03 15:03:54 UTC
Stefan Bodewig being on vacations, I am going to work on this bug.
Cheers.
Comment 13 Antoine Levy-Lambert 2003-06-03 21:19:29 UTC
With the last nightly build of ant, with javac of jdk 1.3 or javac of jdk 1.4, 
compiling source code installed in paths with embedded spaces resulted in this 
type of error messages from the compiler :
    [javac] error: cannot read: C:dev	estantdir spacentsrcmainorg
pache	oolszipAsiExtraField.java

I have just submitted changes in DefaultCompilerAdapter and in JavacExternal 
which address the remarks of Joe Boon and Anne Kinsella.

It should be in the next nightly build of ant.

Cheers

Antoine
Comment 14 Nathan McMinn 2003-07-01 19:53:45 UTC
I believe that this also occurs when you have a very long classpath.  I am 
using Tomcat 4.1.24 and after adding a couple of jars, whenever I update the 
JSP pages, the compile fails.  When looking at the stack trace, the classpath 
is very long, and truncated.  Is this a result of the same issue, or a new bug?
Comment 15 Antoine Levy-Lambert 2003-07-01 20:46:14 UTC
truncated classpath would be a different bug.
Does your problem happen on Windows ? (problem of environment variable space is 
well-known). Is your problem related to ant, or just to tomcat ?
Antoine
Comment 16 Antoine Levy-Lambert 2003-07-25 07:00:41 UTC
*** Bug 21868 has been marked as a duplicate of this bug. ***
Comment 17 Stefan Bodewig 2003-09-25 09:37:31 UTC
*** Bug 23401 has been marked as a duplicate of this bug. ***