Name: gm110360 Date: 11/15/2002
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
If there are too many open files an attempt to open one more
file causes that file to be deleted by the VM.
REGRESSION. Last worked in version 1.4
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached demo. It first creates 4500 files and then
attempts to open all 4500 files.
On 1.4.1 this will cause files to be deleted, on 1.4.0 it
works ok.
EXPECTED VERSUS ACTUAL BEHAVIOR :
The demo output with 1.4.1_01:
creating files...
#files=4500
opening all files...
#exceptions=2464
#files=2036
which means the VM has deleted 2464 files!!
if the demo is run under 1.4.0 the output is:
creating files...
#files=4500
opening all files...
#exceptions=2464
#files=4500
this is the way is should be.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;
public class Demo
{
File workDir = new File("demo").getAbsoluteFile();
boolean DEBUG = false;
LinkedList openFiles = new LinkedList();
LinkedList allFiles = new LinkedList();
int numExceptions = 0;
Demo()
{
if(workDir.exists()) {
System.out.println("removing \""+workDir+"\"...");
del(workDir);
}
System.out.println("creating files...");
createFiles(workDir);
stats();
System.out.println("opening all files...");
openAllFiles(workDir);
System.out.println("#exceptions="+numExceptions);
stats();
}
void openAllFiles(File dir)
{
Iterator iter = allFiles.iterator();
while (iter.hasNext()) {
try {
openFiles.add(new RandomAccessFile((File)iter.next(), "rw"));
} catch (Exception ex) {
if(DEBUG) System.out.println(openFiles.size() +"; "+ ex.toString());
numExceptions++;
}
}
}
void createFiles(File dir)
{
if(!workDir.exists()) workDir.mkdir();
for(int k = 0; k < 4500; k++) {
try {
File f = new File(workDir, Integer.toString(k)+".tmp");
allFiles.add(f);
RandomAccessFile raf = new RandomAccessFile(f, "rw");
raf.write(0);
raf.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
void stats()
{
if(!workDir.exists()) System.out.println("dir does not exist");
else System.out.println("#files="+workDir.listFiles().length);
}
void del(File file)
{
if(file.isDirectory()) {
File[] f = file.listFiles();
for (int t = 0; t < f.length; t++) del(f[t]);
}
file.delete();
}
public static void main(String[] a)
{
new Demo();
}
}
---------- END SOURCE ----------
Release Regression From : 1.4.0_02
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Review ID: 167122)
======================================================================