JDK-4499199 : Modal dialog doesn't handle exceptions correctly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-09-03
  • Updated: 2001-09-26
  • Resolved: 2001-09-26
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.0 beta3Fixed
Related Reports
Relates :  
Relates :  
Description

Name: biR10147			Date: 09/03/2001

When an exception is thrown on EventDispatchThread from inside of show() method of a modal dialog, this dialog exits its show() method without hiding itself, and finishes secondary message loop.  As a result, it causes an application hang when a modal dialog is displayed during drag and drop operations, even if we refuse to start secondary event loop and throw an exception instead.  In JDK 1.3, throwing an exception on EventDispatchThread doesn't break secondary event loop and doesn't make show() method exit.

Steps to reproduce:

1. Compile and run the test case below.
2. Press the "Show" button to make the modal dialog appear.
3. Press the "Throw" button on the dialog to throw new RuntimeException.
4. Watch "show() ended" message in the console indicating that the show() method has finished without disposing the dialog.
5. Press the "Throw" button again to see the exception being thrown not from secondary event loop.

===================================================
import java.awt.Button;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DialogTest extends Frame {

    public DialogTest() {
        super();
        setSize(200, 100);
        setLocation(50, 50);
        setLayout(new FlowLayout());
        final Dialog dialog = new Dialog(this, true);
        dialog.setSize(150, 100);
        dialog.setLayout(new FlowLayout());
        Button closeButton = new Button("Close");
        Button throwButton = new Button("Throw");
        Button showButton = new Button("Show");
        closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                dialog.hide();
            }
        });
        dialog.add(closeButton);
        throwButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                throw new RuntimeException("New exception");
            }
        });
        dialog.add(throwButton);
        showButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    dialog.show();
                } finally {
                    System.out.println("show() finished");
                }
            }
        });
        add(showButton);
    }

    public static void main(String[] args) {
        (new DialogTest()).setVisible(true);
    }
}
===================================================

###@###.###

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta3 FIXED IN: merlin-beta3 INTEGRATED IN: merlin-beta3
17-09-2004

SUGGESTED FIX ------- EventDispatchThread.java ------- *** /tmp/dYuaafB Wed Sep 19 15:17:58 2001 --- EventDispatchThread.java Wed Sep 19 15:17:57 2001 *************** *** 201,215 **** // Can get and throw only unchecked exceptions } catch (RuntimeException e) { ! if (!handleException(e)) { ! throw e; ! } ! return true; ! } catch (Error e) { ! if (!handleException(e)) { ! throw e; ! } ! return true; } } --- 201,233 ---- // Can get and throw only unchecked exceptions } catch (RuntimeException e) { ! processException(e, modalComponent != null); ! } catch (Error e) { ! processException(e, modalComponent != null); ! } ! return true; ! } ! ! private void processException(Throwable e, boolean isModal) { ! if (!handleException(e)) { ! // See bug ID 4499199. ! // If we are in a modal dialog, we cannot throw ! // an exception for the ThreadGroup to handle (as added ! // in RFE 4063022). If we did, the message pump of ! // the modal dialog would be interrupted. ! // We instead choose to handle the exception ourselves. ! // It may be useful to add either a runtime flag or API ! // later if someone would like to instead dispose the ! // dialog and allow the thread group to handle it. ! if (isModal) { ! System.err.println( ! "Exception occurred during event dispatching:"); ! e.printStackTrace(); ! } else if (e instanceof RuntimeException) { ! throw (RuntimeException)e; ! } else if (e instanceof Error) { ! throw (Error)e; ! } } }
17-09-2004

EVALUATION Fix in Merlin Beta3 ###@###.### 2001-09-12 This was introduced when 4063022 was fixed through the following code in EventDispatchThread.java (SCCS version 1.38): 152c147,149 < throw e; --- > System.err.println( > "Exception occurred during event dispatching:"); > e.printStackTrace(); 155,159d151 < } catch (Error e) { < if (!handleException(e)) { < throw e; < } < return true; Reassigning to Sergey to see if he can suggest a fix. ###@###.### 2001-09-12
12-09-2001