DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29391>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29391

javac task uses user.dir for temporary file instead of java.io.tmpdir

           Summary: javac task uses user.dir for temporary file instead of
                    java.io.tmpdir
           Product: Ant
           Version: 1.6.1
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Core tasks
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


We run our server as a service in the system and the execution of a javac Ant
task results in a file not found exception.  It is a temporary file and the name
end up being /fileNNNN

This call to System.getProperty("user.dir") is returning "/" (not sure why as
the user under which the server is run has HOME=/usr/share/jonas).

I don't know why it uses a System.getProperty("user.dir") and not a
System.getProperty("java.io.tmpdir").  It looks wrong to me... 

Independently of what cause the 'user.dir' to return the wrong value I believe
it should be changed to the 'java.io.tmpdir' one.  There may be cases where the
userid under which the server is run has no home directory assigned or it is not
writable.  And tem files should go to /tmp.


Here it is from Ant 1.6.1 DefaultCompilerAdapter.java:

    protected int executeExternalCompile(String[] args, int firstFileName,
                                         boolean quoteFiles) {
        String[] commandArray = null;
        File tmpFile = null;


        try {
            /*
             * Many system have been reported to get into trouble with
             * long command lines - no, not only Windows .
             *
             * POSIX seems to define a lower limit of 4k, so use a temporary
             * file if the total length of the command line exceeds this limit.
             */
            if (Commandline.toString(args).length() > 4096
                && firstFileName >= 0) {
                PrintWriter out = null;
                try {
                    File userDir = getJavac().getTempdir();
                    if (userDir == null) {
                        String userDirName = System.getProperty("user.dir");
                        userDir = new File(userDirName);
                    }
                    tmpFile = fileUtils.createTempFile("files", "", userDir);
                    tmpFile.deleteOnExit();
                    out = new PrintWriter(new FileWriter(tmpFile));
                    for (int i = firstFileName; i < args.length; i++) {
                        if (quoteFiles && args[i].indexOf(" ") > -1) {
                            args[i] = args[i].replace('\\', '/');
                            out.println("\"" + args[i] + "\"");
                        } else {
                            out.println(args[i]);
                        }
                    }
                    out.flush();
                    commandArray = new String[firstFileName + 1];
                    System.arraycopy(args, 0, commandArray, 0, firstFileName);
                    commandArray[firstFileName] = "@" + tmpFile;
                } catch (IOException e) {
                    throw new BuildException("Error creating temporary file",  
   <========= EXCEPTION THROWN HERE
                                             e, location);

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to