I discoverd this while building libgcj with gjar: it can't cope with a
directory with many files because it doesn't close files it opens.

jar: internal error:
java.io.FileNotFoundException: poo/file41105 (Too many open files)
   at gnu.java.nio.channels.FileChannelImpl.open(natFileChannelImpl.cc:178)
   at gnu.java.nio.channels.FileChannelImpl.<init>(FileChannelImpl.java:118)
   at gnu.java.nio.channels.FileChannelImpl.create(FileChannelImpl.java:111)
   at java.io.FileInputStream.<init>(FileInputStream.java:110)
   at gnu.classpath.tools.jar.Creator.writeFile(Creator.java:152)
   at gnu.classpath.tools.jar.Creator.writeCommandLineEntries(Creator.java:202)
   at gnu.classpath.tools.jar.Creator.writeCommandLineEntries(Creator.java:228)
   at gnu.classpath.tools.jar.Creator.run(Creator.java:245)
   at gnu.classpath.tools.jar.Main.run(Main.java:249)
   at gnu.classpath.tools.jar.Main.main(Main.java:257)

I guess this error may be replicated in several places in Classpath
tools, but this one fixes the obvious problem.  No, we can't depend on
finalizers to manage very scarce reources!  :-)

Andrew.


2006-12-14  Andrew Haley  <[EMAIL PROTECTED]>

        * tools/gnu/classpath/tools/jar/Creator.java: Close the
        inputStream.

Index: Creator.java
===================================================================
--- Creator.java        (revision 119819)
+++ Creator.java        (working copy)
@@ -142,15 +142,18 @@
       throws IOException
   {
     boolean isDirectory = file.isDirectory();
-    InputStream inputStream = null;
     if (isDirectory)
       {
         if (filename.charAt(filename.length() - 1) != '/')
           filename += '/';
+       writeFile(isDirectory, null, filename, verbose);
       }
     else
-      inputStream = new FileInputStream(file);
-    writeFile(isDirectory, inputStream, filename, verbose);
+      {
+       InputStream inputStream = new FileInputStream(file);
+       writeFile(isDirectory, inputStream, filename, verbose);
+       inputStream.close();
+      }
   }
 
   private void addEntries(ArrayList result, Entry entry)

Reply via email to