# HG changeset patch # User vadim # Date 1432644715 -10800 # Tue May 26 15:51:55 2015 +0300 # Node ID 9895cb821ab178b25dbe65bda0612c35bcd3395c # Parent e7a68bd4332b5e99b46b1803722e461757a15a9d RT-46083: TimelineClipCore exceptions handling improvent diff --git a/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java b/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java --- a/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java +++ b/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java @@ -231,4 +231,20 @@ results.addAll(ExpressionHelperUtility.getInvalidationListeners(value)); return results; } + + // methods for temporary setting UncaughtExceptionHandler + public static Thread.UncaughtExceptionHandler setHandler() { + Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); + Thread.currentThread().setUncaughtExceptionHandler((Thread t, Throwable e) -> { + e.printStackTrace(); + throw new AssertionError(e); + }); + return exceptionHandler; + } + + // the test should call this method in the finally block to ensure + // that the handler is reset + public static void resetHandler(Thread.UncaughtExceptionHandler exceptionHandler) { + Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); + } } diff --git a/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java b/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java --- a/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java @@ -39,6 +39,7 @@ import com.sun.javafx.PlatformUtil; import com.sun.javafx.util.Utils; import com.sun.javafx.scene.control.behavior.ListViewAnchorRetriever; +import com.sun.javafx.scene.control.infrastructure.ControlTestUtils; import com.sun.javafx.scene.control.infrastructure.KeyEventFirer; import com.sun.javafx.scene.control.infrastructure.KeyModifier; import com.sun.javafx.scene.control.infrastructure.StageLoader; @@ -1979,11 +1980,6 @@ } @Test public void test_rt36800() { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!")); - final int items = 10; listView.getItems().clear(); for (int i = 0; i < items; i++) { @@ -2002,7 +1998,13 @@ keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0 - keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); + try { + keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + } finally { + ControlTestUtils.resetHandler(exceptionHandler); + } assertEquals(0, getAnchor()); assertTrue(fm.isFocused(0)); @@ -2012,17 +2014,9 @@ assertFalse(sm.isSelected(3)); assertFalse(sm.isSelected(4)); assertFalse(sm.isSelected(5)); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); } @Test public void test_rt_36942() { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!")); - final int items = 3; listView.getItems().clear(); for (int i = 0; i < items; i++) { @@ -2042,12 +2036,15 @@ sm.select(0); keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1 keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2 - keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception? + + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); + try { + keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception? + } finally { + ControlTestUtils.resetHandler(exceptionHandler); + } sl.dispose(); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); } @Test public void test_rt_37130_pageUpAtTop() { diff --git a/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java b/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java --- a/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java @@ -25,6 +25,7 @@ package javafx.scene.control; +import com.sun.javafx.scene.control.infrastructure.ControlTestUtils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -1170,22 +1171,18 @@ } @Test public void test_rt40804() { - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> { - e.printStackTrace(); - fail("We don't expect any exceptions in this test!"); - }); - StageLoader sl = new StageLoader(currentControl); model.setSelectionMode(SelectionMode.MULTIPLE); model.select(0); model.select(1); model.clearSelection(); - model.select(3); // this is where the test failed + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); + try { + model.select(3); // this is where the test failed + } finally { + ControlTestUtils.resetHandler(exceptionHandler); + } sl.dispose(); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); } } diff --git a/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java b/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java --- a/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java @@ -40,6 +40,7 @@ import com.sun.javafx.PlatformUtil; import com.sun.javafx.util.Utils; import com.sun.javafx.scene.control.behavior.TableViewAnchorRetriever; +import com.sun.javafx.scene.control.infrastructure.ControlTestUtils; import com.sun.javafx.scene.control.infrastructure.KeyEventFirer; import com.sun.javafx.scene.control.infrastructure.KeyModifier; import com.sun.javafx.scene.control.infrastructure.StageLoader; @@ -3474,11 +3475,6 @@ } private void test_rt36800(boolean cellSelection) { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!")); - final int items = 10; tableView.getItems().clear(); for (int i = 0; i < items; i++) { @@ -3510,7 +3506,13 @@ keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0 - keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); + try { + keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + } finally { + ControlTestUtils.resetHandler(exceptionHandler); + } if (cellSelection) { assertEquals(0, getAnchor().getRow()); @@ -3532,17 +3534,9 @@ assertFalse(sm.isSelected(4)); assertFalse(sm.isSelected(5)); } - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); } @Test public void test_rt_36942() { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!")); - final int items = 3; tableView.getItems().clear(); for (int i = 0; i < items; i++) { @@ -3567,12 +3561,15 @@ sm.select(0); keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1 keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2 - keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception? + + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); + try { + keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception? + } finally { + ControlTestUtils.resetHandler(exceptionHandler); + } sl.dispose(); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); } @Test public void test_rt_37130_pageUpAtTop() { diff --git a/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java b/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java --- a/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java @@ -78,6 +78,7 @@ import org.junit.Test; import com.sun.javafx.scene.control.TableColumnComparatorBase.TableColumnComparator; +import com.sun.javafx.scene.control.infrastructure.ControlTestUtils; import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils; import com.sun.javafx.scene.control.test.Person; import com.sun.javafx.scene.control.test.RT_22463_Person; @@ -3549,11 +3550,6 @@ } @Test public void test_rt_37429() { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!")); - // table columns - 1 column; name TableColumn nameColumn = new TableColumn<>("name"); nameColumn.setCellValueFactory(param -> new ReadOnlyObjectWrapper(param.getValue())); @@ -3578,15 +3574,15 @@ } }); + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); StageLoader sl = new StageLoader(table); - - table.getSelectionModel().select(0); - table.getSortOrder().add(nameColumn); - - sl.dispose(); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); + try { + table.getSelectionModel().select(0); + table.getSortOrder().add(nameColumn); + } finally { + sl.dispose(); + ControlTestUtils.resetHandler(exceptionHandler); + } } private int rt_37429_items_change_count = 0; diff --git a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java --- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java @@ -38,6 +38,7 @@ import com.sun.javafx.PlatformUtil; import com.sun.javafx.util.Utils; import com.sun.javafx.scene.control.behavior.TreeTableViewAnchorRetriever; +import com.sun.javafx.scene.control.infrastructure.ControlTestUtils; import com.sun.javafx.scene.control.infrastructure.KeyEventFirer; import com.sun.javafx.scene.control.infrastructure.KeyModifier; import com.sun.javafx.scene.control.infrastructure.StageLoader; @@ -4001,14 +4002,6 @@ } private void test_rt36800(boolean cellSelection) { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> { - e.printStackTrace(); - fail("We don't expect any exceptions in this test!"); - }); - final int items = 10; root.getChildren().clear(); root.setExpanded(true); @@ -4041,7 +4034,13 @@ keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0 - keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); + try { + keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + } finally { + ControlTestUtils.resetHandler(exceptionHandler); + } if (cellSelection) { assertEquals(0, getAnchor().getRow()); @@ -4063,9 +4062,6 @@ assertFalse(sm.isSelected(4)); assertFalse(sm.isSelected(5)); } - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); } @Test public void test_rt_37130_pageUpAtTop() { diff --git a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewTest.java b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewTest.java --- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewTest.java @@ -83,6 +83,7 @@ import org.junit.Test; import com.sun.javafx.scene.control.TableColumnComparatorBase.TreeTableColumnComparator; +import com.sun.javafx.scene.control.infrastructure.ControlTestUtils; import com.sun.javafx.scene.control.infrastructure.StageLoader; import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils; import com.sun.javafx.scene.control.skin.VirtualScrollBar; @@ -3616,14 +3617,6 @@ } @Test public void test_rt_37429() { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> { - e.printStackTrace(); - fail("We don't expect any exceptions in this test!"); - }); - // table items - 3 items, 2nd item has 2 children TreeItem root = new TreeItem<>(); @@ -3661,15 +3654,16 @@ } }); + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); StageLoader sl = new StageLoader(table); - table.getSelectionModel().select(0); - table.getSortOrder().add(nameColumn); - - sl.dispose(); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); + try { + table.getSelectionModel().select(0); + table.getSortOrder().add(nameColumn); + } finally { + sl.dispose(); + ControlTestUtils.resetHandler(exceptionHandler); + } } private int rt_37429_items_change_count = 0; diff --git a/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java b/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java --- a/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java @@ -35,6 +35,7 @@ import com.sun.javafx.PlatformUtil; import com.sun.javafx.util.Utils; import com.sun.javafx.scene.control.behavior.TreeViewAnchorRetriever; +import com.sun.javafx.scene.control.infrastructure.ControlTestUtils; import com.sun.javafx.scene.control.infrastructure.KeyEventFirer; import com.sun.javafx.scene.control.infrastructure.KeyModifier; import com.sun.javafx.scene.control.infrastructure.StageLoader; @@ -2192,11 +2193,6 @@ } @Test public void test_rt36800() { - // get the current exception handler before replacing with our own, - // as ListListenerHelp intercepts the exception otherwise - final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler(); - Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!")); - final int items = 10; root.getChildren().clear(); root.setExpanded(true); @@ -2216,7 +2212,13 @@ keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1 keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0 - keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + + final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler(); + try { + keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time? + } finally { + ControlTestUtils.resetHandler(exceptionHandler); + } assertEquals(0, getAnchor()); assertTrue(fm.isFocused(0)); @@ -2226,9 +2228,6 @@ assertFalse(sm.isSelected(3)); assertFalse(sm.isSelected(4)); assertFalse(sm.isSelected(5)); - - // reset the exception handler - Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler); } @Test public void test_rt_37130_pageUpAtTop() { diff --git a/modules/graphics/src/main/java/com/sun/scenario/animation/shared/TimelineClipCore.java b/modules/graphics/src/main/java/com/sun/scenario/animation/shared/TimelineClipCore.java --- a/modules/graphics/src/main/java/com/sun/scenario/animation/shared/TimelineClipCore.java +++ b/modules/graphics/src/main/java/com/sun/scenario/animation/shared/TimelineClipCore.java @@ -225,7 +225,7 @@ try { onFinished.handle(new ActionEvent(kf, null)); } catch (Throwable ex) { - ex.printStackTrace(); + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex); } } } diff --git a/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java b/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java --- a/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java +++ b/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java @@ -691,7 +691,7 @@ try { animationRunnable.run(); } catch (Throwable t) { - t.printStackTrace(); + Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t); } } }