Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8203047: [macosx] java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java fails #3749

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -189,7 +189,6 @@ java/awt/datatransfer/SystemFlavorMap/AddFlavorTest.java 8079268 linux-all
java/awt/Toolkit/ScreenInsetsTest/ScreenInsetsTest.java 6829250 windows-all
java/awt/Toolkit/RealSync/Test.java 6849383 linux-all
java/awt/LightweightComponent/LightweightEventTest/LightweightEventTest.java 8159252 windows-all
java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java 8203047 macosx-all
java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.java 8073636 macosx-all
java/awt/FullScreen/FullScreenInsets/FullScreenInsets.java 7019055 windows-all,linux-all
java/awt/Focus/8013611/JDK8013611.java 8175366 windows-all,macosx-all
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -43,118 +43,126 @@

private static volatile boolean exceptionHandled = false;
private static volatile boolean mousePressed = false;
private static Frame f = null;
private static Dialog d = null;

public static void main(String[] args)
{
final Thread.UncaughtExceptionHandler eh = new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException(Thread t, Throwable e)
try {
final Thread.UncaughtExceptionHandler eh = new Thread.UncaughtExceptionHandler()
{
if (e.getMessage().equals(EXCEPTION_MESSAGE))
@Override
public void uncaughtException(Thread t, Throwable e)
{
exceptionHandled = true;
if (e.getMessage().equals(EXCEPTION_MESSAGE))
{
exceptionHandled = true;
}
}
}
};

Frame f = new Frame("F");
f.setBounds(100, 100, 400, 300);
// set exception handler for EDT
f.addWindowListener(new WindowAdapter()
{
@Override
public void windowOpened(WindowEvent we)
};

f = new Frame("F");
f.setBounds(100, 100, 400, 300);
// set exception handler for EDT
f.addWindowListener(new WindowAdapter()
{
Thread edt = Thread.currentThread();
edt.setUncaughtExceptionHandler(eh);
}
});
f.setVisible(true);
@Override
public void windowOpened(WindowEvent we)
{
Thread edt = Thread.currentThread();
edt.setUncaughtExceptionHandler(eh);
}
});
f.setVisible(true);

Robot r = Util.createRobot();
Util.waitForIdle(r);
Robot r = Util.createRobot();
Util.waitForIdle(r);
r.delay(1000);

// check exception without modal dialog
MouseListener exceptionListener = new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent me)
// check exception without modal dialog
MouseListener exceptionListener = new MouseAdapter()
{
throw new RuntimeException(EXCEPTION_MESSAGE);
@Override
public void mousePressed(MouseEvent me)
{
throw new RuntimeException(EXCEPTION_MESSAGE);
}
};
f.addMouseListener(exceptionListener);

exceptionHandled = false;
Point fp = f.getLocationOnScreen();
r.mouseMove(fp.x + f.getWidth() / 2, fp.y + f.getHeight() / 2);
Util.waitForIdle(r);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
f.removeMouseListener(exceptionListener);

if (!exceptionHandled)
{
throw new RuntimeException("Test FAILED: exception is not handled for frame");
}
};
f.addMouseListener(exceptionListener);

exceptionHandled = false;
Point fp = f.getLocationOnScreen();
r.mouseMove(fp.x + f.getWidth() / 2, fp.y + f.getHeight() / 2);
Util.waitForIdle(r);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
f.removeMouseListener(exceptionListener);

if (!exceptionHandled)
{
throw new RuntimeException("Test FAILED: exception is not handled for frame");
}

// check exception with modal dialog
final Dialog d = new Dialog(f, "D", true);
d.setBounds(fp.x + 100, fp.y + 100, 400, 300);
d.addMouseListener(exceptionListener);
EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
// check exception with modal dialog
d = new Dialog(f, "D", true);
d.setBounds(fp.x + 100, fp.y + 100, 400, 300);
d.addMouseListener(exceptionListener);
EventQueue.invokeLater(new Runnable()
{
d.setVisible(true);
@Override
public void run()
{
d.setVisible(true);
}
});
Util.waitForIdle(r);
r.delay(1000);

exceptionHandled = false;
Point dp = d.getLocationOnScreen();
r.mouseMove(dp.x + d.getWidth() / 2, dp.y + d.getHeight() / 2);
Util.waitForIdle(r);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
d.removeMouseListener(exceptionListener);

if (!exceptionHandled)
{
throw new RuntimeException("Test FAILED: exception is not handled for modal dialog");
}
});
Util.waitForIdle(r);

exceptionHandled = false;
Point dp = d.getLocationOnScreen();
r.mouseMove(dp.x + d.getWidth() / 2, dp.y + d.getHeight() / 2);
Util.waitForIdle(r);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
d.removeMouseListener(exceptionListener);

if (!exceptionHandled)
{
throw new RuntimeException("Test FAILED: exception is not handled for modal dialog");
}

// check the dialog is still modal
MouseListener pressedListener = new MouseAdapter()
{
@Override
public void mousePressed(MouseEvent me)
// check the dialog is still modal
MouseListener pressedListener = new MouseAdapter()
{
mousePressed = true;
@Override
public void mousePressed(MouseEvent me)
{
mousePressed = true;
}
};
f.addMouseListener(pressedListener);

mousePressed = false;
r.mouseMove(fp.x + 50, fp.y + 50);
Util.waitForIdle(r);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
f.removeMouseListener(pressedListener);

if (mousePressed)
{
throw new RuntimeException("Test FAILED: modal dialog is not modal or visible after exception");
}
} finally {
// dispose frame and dialog
if (f != null && d != null) {
d.dispose();
f.dispose();
}
};
f.addMouseListener(pressedListener);

mousePressed = false;
r.mouseMove(fp.x + 50, fp.y + 50);
Util.waitForIdle(r);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Util.waitForIdle(r);
f.removeMouseListener(pressedListener);

if (mousePressed)
{
throw new RuntimeException("Test FAILED: modal dialog is not modal or visible after exception");
}

// test is passed
d.dispose();
f.dispose();
}
}