JDK-5071352 : com/sun/tools/javac/util/Paths$Path.addJarClassPath problem
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2004-07-03
  • Updated: 2004-07-21
  • Resolved: 2004-07-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b59Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
We have encountered a problem in javac that we would like to
have addressed with some urgency.

The problem involves jarfiles and the closing of such files.
To speed up compilation time for several of our products, a
lot of compilation is done "in process" from ant-scripts, i.e.,
the main-method in javac is called with Method.invoke instead
of spawning out a new process with Runtime.exec.

Problem is with method addJarClassPath in com/sun/tools/javac/util/Paths$Path.
This method looks like this (in b57):

private void addJarClassPath(String jarFileName, boolean warn) {
     try {
    String jarParent = new File(jarFileName).getParent();
    JarFile jar = new JarFile(jarFileName);

    Manifest man = jar.getManifest();
    if (man == null) return;

    Attributes attr = man.getMainAttributes();
    if (attr == null) return;

    String path = attr.getValue(Attributes.Name.CLASS_PATH);
    if (path == null) return;

    for (StringTokenizer st = new StringTokenizer(path);
         st.hasMoreTokens();) {
        String elt = st.nextToken();
        if (jarParent != null)
        elt = new File(jarParent, elt).toString();
        addFile(elt, warn);
    }
     } catch (IOException e) {
    log.error(Position.NOPOS,
          "error.reading.file", jarFileName, e);
     }
}

This method creates a new JarFile, but does not call close on
it.  This means that it relies on finalization to take place
to close the JarFile.  Since JarFile is a ZipFile, reading
the javadoc for ZipFile says:

    Since the time when GC would invoke this method is undetermined, it is
    strongly recommended that applications invoke the close method as soon
    they have finished accessing this ZipFile. This will prevent holding up
    system resources for an undetermined length of time.

I have attached a test case in a jar: javacbug.jar.  Unjar and
read README.txt for instructions.

Note that this problem is not a theoretical one, it is actually
blocking us to some extent and gives us unpredictability in our
builds at the moment.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b59 tiger-rc
03-08-2004

PUBLIC COMMENTS -
03-08-2004

EVALUATION I agree that a close() should be added to the code. There are probably other places in the JDK where close() should be added, since IIRC this code was adapted from elsewhere. I believe the more serious problem was fixed by 5010739: ZipFile objects are never garbage collected and modulo that bug, adding a close() is just a resouce optimization issue. ###@###.### 2004-07-06 -- BEA strongly disagrees that this is a "resource optimization issue". It is not a case where they, if they run out of file handles, can do a GC and hope that finalization will occur and free these. In their case, and in their test case, the file cannot be deleted unless a garbage collection and finalization has occured on the JarFile in question. What should a JVM do if a File.delete() fails? Run a garbage collection and hope for finalization? This doesn't seem to make sense here, or does it? Please consider fixing this in Tiger by way of exception. This issue is creating substantial unpredictability in BEA's Tiger builds, which translates to negative business impact for them. ###@###.### 2004-07-14
14-07-2004