JDK-4779905 : REGRESSION: If there are too many open files 1.4.1 deletes files
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.0,1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2002-11-15
  • Updated: 2003-08-13
  • Resolved: 2003-08-13
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
1.4.2 1.4.2Fixed
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.4.2 FIXED IN: 1.4.2 INTEGRATED IN: 1.4.2
14-06-2004

EVALUATION Probably related to a workaround for opening hidden files introduced in Hopper. Still investigating. ###@###.### 2002-11-15 I believe this problem was resolved by the move to the CreateFile API, since the workaround involving hidden files is no longer in place. The VM currently crashes if it runs out of file descriptors so it is hard to verify this is the case. ###@###.### 2002-11-19
19-11-2002