JFileChooser in JWS app (1.6) leaves file handles open on Windows
We have discovered that the JFileChooser is sometimes leaving File Handles open (the current directory) on Windows XP, such that you cannot delete the directory after you have closed the JFileChooser or switched to other directories. This is only happening when running with Java Web Start JRE 1.6 and when setCurrentDirectory() is called in code, but only at what seems to be random times. This hasn't been reproduced when launched as normal app with java -jar or javaw -jar.
Anyone have any ideas? I didn't see any bugs on this.
Steps to reproduce:
1. compile and deploy the JdkError class below as a JWS app.
2. launch the app on a Windows XP system.
3. Use procexp to monitor the file handles of the javaw.exe.
http://www.microsoft.com/technet/sysinternals/utilities/ProcessExplorer.mspx
4. Select a sub directory in file chooser, and click cancel
5. look in procexp for an additional C:\ file entry
6. repeat step 4 and 5 at least 10 times using different directories, eventually you'll start to see additional C:\ file handles showing up.
To close the the file chooser, just pick a file and click OK.
You can change the code to use a another directory to see that you cannot delete the directory even after the file chooser is closed (but the app frame is still running). The file handles do obviously clear when the process is killed.
This has been confirmed on a couple of different systems, all running XP, but different CPU/Memory configurations.
Not sure what to do to confirm it on Linux. I'm going to start by just checkin for leftover fd links?
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JdkError
{
public static void main(String[] args)
{
try
{
final JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.setSize(new Dimension(500, 500));
frame.setVisible(true);
final JFileChooser chooser = new JFileChooser();
int ret = chooser.showOpenDialog(frame);
while (ret != JFileChooser.APPROVE_OPTION)
{
chooser.setCurrentDirectory(new File("C:\\"));
ret = chooser.showOpenDialog(frame);
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}