8284993: Replace System.exit call in swing tests with RuntimeException

Reviewed-by: azvegint
This commit is contained in:
Prasanta Sadhukhan 2022-04-22 06:48:01 +00:00
parent d84b9c5489
commit 80219a48c3
6 changed files with 25 additions and 11 deletions

View File

@ -37,10 +37,24 @@ import javax.swing.SwingUtilities;
public class Test8019180 implements Runnable {
private static final CountDownLatch LATCH = new CountDownLatch(1);
private static final String[] ITEMS = {"First", "Second", "Third", "Fourth"};
private static JFrame frame;
private static boolean selectionFail = false;
public static void main(String[] args) throws InterruptedException {
SwingUtilities.invokeLater(new Test8019180());
LATCH.await();
public static void main(String[] args) throws Exception {
try {
SwingUtilities.invokeLater(new Test8019180());
LATCH.await();
System.out.println("selectionFail " + selectionFail);
if (selectionFail) {
throw new RuntimeException("Combobox not selected");
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
private JComboBox<String> test;
@ -50,8 +64,9 @@ public class Test8019180 implements Runnable {
if (this.test == null) {
this.test = new JComboBox<>(ITEMS);
this.test.addActionListener(this.test);
JFrame frame = new JFrame();
frame = new JFrame();
frame.add(test);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
SwingUtilities.invokeLater(this);
@ -60,9 +75,8 @@ public class Test8019180 implements Runnable {
this.test.setSelectedIndex(1 + index);
if (0 > this.test.getSelectedIndex()) {
System.err.println("ERROR: no selection");
System.exit(8019180);
selectionFail = true;
}
SwingUtilities.getWindowAncestor(this.test).dispose();
LATCH.countDown();
}
}

View File

@ -118,6 +118,6 @@ public class Test8013442 extends FileFilter implements Runnable, Thread.Uncaught
public void uncaughtException(Thread thread, Throwable throwable) {
throwable.printStackTrace();
System.exit(1);
throw new RuntimeException(throwable);
}
}

View File

@ -41,7 +41,7 @@ public class Test6943780 implements Runnable, Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
throwable.printStackTrace();
System.exit(1);
throw new RuntimeException(throwable);
}
@Override

View File

@ -94,6 +94,6 @@ public class Test8015926 implements TreeModelListener, Runnable, Thread.Uncaught
@Override
public void uncaughtException(Thread thread, Throwable exception) {
exception.printStackTrace();
System.exit(1);
throw new RuntimeException(exception);
}
}

View File

@ -68,7 +68,7 @@ public class Test6968363 implements Runnable, Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
throwable.printStackTrace();
System.exit(1);
throw new RuntimeException(throwable);
}
@Override

View File

@ -65,7 +65,7 @@ public class Test8017492 {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
throwable.printStackTrace();
System.exit(1);
throw new RuntimeException(throwable);
}
});
thread.start();