开发者

1/10 times java crashes on JFileChooser.showOpenDialog

开发者 https://www.devze.com 2023-01-30 21:38 出处:网络
Non-reproducable crash (no erro开发者_JAVA技巧r/exception). Happens when I run a dialog to select a folder only 1 out of 10 times. Code:

Non-reproducable crash (no erro开发者_JAVA技巧r/exception). Happens when I run a dialog to select a folder only 1 out of 10 times. Code:

public String getFilePathFromDialog(String dialogTitle) {
    JFileChooser fileChooser;
    fileChooser = new JFileChooser();
    fileChooser.setDialogTitle(dialogTitle);
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fileChooser.setAcceptAllFileFilterUsed(true);
    if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        return fileChooser.getSelectedFile().toString();
    } else {
        return "";
    }
}

It crashes my application. After this I can only close it with: Ctrl+Alt+Delete -> Task Manager -> Kill it -> Then I get "Java(TM) Platform SE binary is not responding" and I hit Close button

Am I doing something wrong or is it a bug?

I found the crash dump file as Peter mentioned below. Here is some of it:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x62a5ff52, pid=5516, tid=5312
#
# Problematic frame:
# C  [nvd3dum.dll+0x2fff52]
#
Current thread (0x04323400):  JavaThread "AWT-Windows" daemon [_thread_in_native, id=5312, stack(0x04d60000,0x04db0000)]
siginfo: ExceptionCode=0xc0000005, writing address 0x04ee9004


# Problematic frame:
# C  [nvd3dum.dll+0x2fff52]

That'll be your NVidia video driver?

Note this is not on the AWT EDT thread, but an internal system thread. You might try disabling Direct Draw 3D (there is some system property for doing that).


I've seen something like this on Windows when the JVM was running very close the maximum memory allocated allocated to it by the OS. The user then opens a dialog, possibly on a network drive, this loads some additional OS resources (perhaps DLLs), and then the JVM runs out of memory (not heap but memory allocated to the JVM itself) and then crashes.


Make sure that the code is invoked on EDT.

Also, just an observation (nothing to do with the crash), it is better to declare variable fileChooser and assign it in the same statement (immutability):

final JFileChooser fileChooser = new JFileChooser();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号