changeset 9074:250e673f1978

RT-46083: TimelineClipCore exceptions handling improvent Reviewed-by: flar, jgiles
author vadim
date Sat, 30 May 2015 15:00:29 +0300
parents 42facc96934d
children d352eeca1c89
files modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java modules/controls/src/test/java/javafx/scene/chart/AreaChartTest.java modules/controls/src/test/java/javafx/scene/chart/ChartTestBase.java modules/controls/src/test/java/javafx/scene/chart/StackedAreaChartTest.java modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeTableViewTest.java modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java modules/graphics/src/main/java/com/sun/scenario/animation/shared/TimelineClipCore.java modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java
diffstat 12 files changed, 103 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/com/sun/javafx/scene/control/infrastructure/ControlTestUtils.java	Sat May 30 15:00:29 2015 +0300
@@ -231,4 +231,53 @@
         results.addAll(ExpressionHelperUtility.getInvalidationListeners(value));
         return results;
     }
+
+    // methods for temporary setting UncaughtExceptionHandler
+    public static ExceptionHandler setHandler() {
+        return new ExceptionHandler();
+    }
+
+    public static class ExceptionHandler implements Thread.UncaughtExceptionHandler {
+        private Throwable cause = null;
+        private Thread.UncaughtExceptionHandler oldHandler;
+
+        public ExceptionHandler() {
+            this.oldHandler = Thread.currentThread().getUncaughtExceptionHandler();
+            Thread.currentThread().setUncaughtExceptionHandler(this);
+        }
+
+        @Override
+        public void uncaughtException(Thread t, Throwable e) {
+            e.printStackTrace();
+            cause = e;
+        }
+
+        public void checkException() {
+            if (cause != null) {
+                if (cause instanceof Error) {
+                    throw (Error) cause;
+                } else if (cause instanceof RuntimeException) {
+                    throw (RuntimeException) cause;
+                } else {
+                    throw new AssertionError(cause);
+                }
+            }
+        }
+
+        // the test should call this method in the finally block to ensure
+        // that the handler is reset
+        public void resetHandler() {
+            Thread.currentThread().setUncaughtExceptionHandler(oldHandler);
+        }
+    }
+
+    public static void runWithExceptionHandler(Runnable r) {
+        ExceptionHandler myHandler = new ExceptionHandler();
+        try {
+            r.run();
+        } finally {
+            myHandler.resetHandler();
+        }
+        myHandler.checkException();
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/chart/AreaChartTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/chart/AreaChartTest.java	Sat May 30 15:00:29 2015 +0300
@@ -26,6 +26,7 @@
 package javafx.scene.chart;
 
 
+import com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
@@ -145,35 +146,18 @@
          assertEquals(5, countSymbols(ac, "chart-area-symbol"));
      }
 
-    boolean writeWasCalled = false;
     @Test
     public void testDataWithoutSymbolsAddWithAnimation_rt_39353() {
         startApp();
+        ac.getData().addAll(series1);
         ac.setAnimated(true);
         ac.setCreateSymbols(false);
-        ac.getData().addAll(series1);
         series1.getData().add(new XYChart.Data(40d,10d));
-        final PrintStream defaultErrorStream = System.err;
-        final PrintStream errChecker = new PrintStream(new OutputStream() {
-            @Override
-            public void write(int b) throws IOException {
-                writeWasCalled = true;
-            }
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            toolkit.setAnimationTime(0);
+            // check remove just in case
+            series1.getData().remove(0);
+            toolkit.setAnimationTime(800);
         });
-        try {
-            System.setErr(errChecker);
-        } catch (SecurityException ex) {
-            // ignore
-        }
-        toolkit.setAnimationTime(0);
-        // check remove just in case
-        series1.getData().remove(0);
-        toolkit.setAnimationTime(800);
-        try {
-            System.setErr(defaultErrorStream);
-        } catch (SecurityException ex) {
-            // ignore
-        }
-        assertTrue(!writeWasCalled);
     }
 }
--- a/modules/controls/src/test/java/javafx/scene/chart/ChartTestBase.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/chart/ChartTestBase.java	Sat May 30 15:00:29 2015 +0300
@@ -67,6 +67,7 @@
         stage = new Stage();
         stage.setScene(scene);
         stage.show();
+        toolkit.setAnimationTime(0);
         pulse();
     }
     
--- a/modules/controls/src/test/java/javafx/scene/chart/StackedAreaChartTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/chart/StackedAreaChartTest.java	Sat May 30 15:00:29 2015 +0300
@@ -26,6 +26,7 @@
 package javafx.scene.chart;
 
 
+import com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
@@ -429,35 +430,18 @@
         assertEquals(15, yAxis.dataMaxValue, 1e-100);
     }
     
-    boolean writeWasCalled = false;
     @Test
     public void testDataWithoutSymbolsAddWithAnimation_rt_39353() {
         startApp();
+        ac.getData().addAll(series1);
         ac.setAnimated(true);
         ac.setCreateSymbols(false);
-        ac.getData().addAll(series1);
         series1.getData().add(new XYChart.Data(40d,10d));
-        final PrintStream defaultErrorStream = System.err;
-        final PrintStream errChecker = new PrintStream(new OutputStream() {
-            @Override
-            public void write(int b) throws IOException {
-                writeWasCalled = true;
-            }
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            toolkit.setAnimationTime(0);
+            // check remove just in case
+            series1.getData().remove(0);
+            toolkit.setAnimationTime(800);
         });
-        try {
-            System.setErr(errChecker);
-        } catch (SecurityException ex) {
-            // ignore
-        }
-        toolkit.setAnimationTime(0);
-        // check remove just in case
-        series1.getData().remove(0);
-        toolkit.setAnimationTime(800);
-        try {
-            System.setErr(defaultErrorStream);
-        } catch (SecurityException ex) {
-            // ignore
-        }
-        assertTrue(!writeWasCalled);
     }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java	Sat May 30 15:00:29 2015 +0300
@@ -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,10 @@
         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?
+
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
+        });
 
         assertEquals(0, getAnchor());
         assertTrue(fm.isFocused(0));
@@ -2012,17 +2011,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 +2033,12 @@
         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?
+
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception?
+        });
 
         sl.dispose();
-
-        // reset the exception handler
-        Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
     }
 
     @Test public void test_rt_37130_pageUpAtTop() {
--- a/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java	Sat May 30 15:00:29 2015 +0300
@@ -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,15 @@
     }
 
     @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
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            model.select(3); // this is where the test failed
+        });
 
         sl.dispose();
-
-        // reset the exception handler
-        Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
     }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java	Sat May 30 15:00:29 2015 +0300
@@ -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,10 @@
         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?
+
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
+        });
 
         if (cellSelection) {
             assertEquals(0, getAnchor().getRow());
@@ -3532,17 +3531,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 +3558,12 @@
         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?
+
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception?
+        });
 
         sl.dispose();
-
-        // reset the exception handler
-        Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
     }
 
     @Test public void test_rt_37130_pageUpAtTop() {
--- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java	Sat May 30 15:00:29 2015 +0300
@@ -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,10 @@
         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?
+
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
+        });
 
         if (cellSelection) {
             assertEquals(0, getAnchor().getRow());
@@ -4063,9 +4059,6 @@
             assertFalse(sm.isSelected(4));
             assertFalse(sm.isSelected(5));
         }
-
-        // reset the exception handler
-        Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
     }
 
     @Test public void test_rt_37130_pageUpAtTop() {
--- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewTest.java	Sat May 30 15:00:29 2015 +0300
@@ -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<String> root = new TreeItem<>();
 
@@ -3663,13 +3656,12 @@
 
         StageLoader sl = new StageLoader(table);
 
-        table.getSelectionModel().select(0);
-        table.getSortOrder().add(nameColumn);
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            table.getSelectionModel().select(0);
+            table.getSortOrder().add(nameColumn);
+        });
 
         sl.dispose();
-
-        // reset the exception handler
-        Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
     }
 
     private int rt_37429_items_change_count = 0;
--- a/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java	Sat May 30 15:00:29 2015 +0300
@@ -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,10 @@
         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?
+
+        ControlTestUtils.runWithExceptionHandler(() -> {
+            keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
+        });
 
         assertEquals(0, getAnchor());
         assertTrue(fm.isFocused(0));
@@ -2226,9 +2225,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() {
--- a/modules/graphics/src/main/java/com/sun/scenario/animation/shared/TimelineClipCore.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/graphics/src/main/java/com/sun/scenario/animation/shared/TimelineClipCore.java	Sat May 30 15:00:29 2015 +0300
@@ -225,7 +225,7 @@
                 try {
                     onFinished.handle(new ActionEvent(kf, null));
                 } catch (Throwable ex) {
-                    ex.printStackTrace();
+                    Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), ex);
                 }
             }
         }
--- a/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java	Fri May 29 20:43:41 2015 -0400
+++ b/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java	Sat May 30 15:00:29 2015 +0300
@@ -691,7 +691,7 @@
             try {
                 animationRunnable.run();
             } catch (Throwable t) {
-                t.printStackTrace();
+                Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t);
             }
         }
     }