8198398: Test javax/swing/JColorChooser/Test6199676.java fails in mach5
authorserb
Tue, 04 Dec 2018 13:09:20 -0800
changeset 52963 1f1c949f55ff
parent 52962 9c0231a493d6
child 52964 840d66c98b6c
8198398: Test javax/swing/JColorChooser/Test6199676.java fails in mach5 Reviewed-by: kaddepalli, prr
test/jdk/ProblemList.txt
test/jdk/javax/swing/JColorChooser/Test6199676.java
test/jdk/javax/swing/JTable/6735286/bug6735286.java
--- a/test/jdk/ProblemList.txt	Fri Nov 30 13:31:31 2018 +0100
+++ b/test/jdk/ProblemList.txt	Tue Dec 04 13:09:20 2018 -0800
@@ -777,8 +777,6 @@
 javax/swing/plaf/basic/BasicComboBoxEditor/Test8015336.java 8198394 generic-all
 javax/swing/plaf/metal/MetalLookAndFeel/Test8039750.java 8198395 generic-all
 javax/swing/text/DevanagariEditor.java 8198397 generic-all
-javax/swing/JColorChooser/Test6199676.java 8198398 generic-all
-javax/swing/JTable/6735286/bug6735286.java 8198398 generic-all
 javax/swing/SpringLayout/4726194/bug4726194.java 8198399 generic-all
 javax/swing/SwingUtilities/6797139/bug6797139.java 8198400 generic-all
 javax/swing/text/html/parser/Parser/6836089/bug6836089.java 8198401 generic-all
--- a/test/jdk/javax/swing/JColorChooser/Test6199676.java	Fri Nov 30 13:31:31 2018 +0100
+++ b/test/jdk/javax/swing/JColorChooser/Test6199676.java	Tue Dec 04 13:09:20 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2018, 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
@@ -23,33 +23,24 @@
 
 /*
  * @test
+ * @key headful
  * @bug 6199676
  * @summary Tests preview panel after L&F changing
- * @author Sergey Malenkov
  */
 
 import java.awt.Component;
 import java.awt.Container;
+
 import javax.swing.JColorChooser;
 import javax.swing.JFrame;
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
-import javax.swing.UIManager.LookAndFeelInfo;
+import javax.swing.UnsupportedLookAndFeelException;
 
 public class Test6199676 implements Runnable {
-    public static void main(String[] args) {
-        SwingUtilities.invokeLater(new Test6199676());
-    }
-
-    private static void exit(String error) {
-        if (error != null) {
-            System.err.println(error);
-            System.exit(1);
-        }
-        else {
-            System.exit(0);
-        }
+    public static void main(String[] args) throws Exception {
+        SwingUtilities.invokeAndWait(new Test6199676());
     }
 
     private static Component getPreview(Container container) {
@@ -74,44 +65,42 @@
         return (component != null) && component.isShowing();
     }
 
-    private int index;
-    private boolean updated;
-    private JColorChooser chooser;
-
     public synchronized void run() {
-        if (this.chooser == null) {
-            this.chooser = new JColorChooser();
-
-            JFrame frame = new JFrame(getClass().getName());
-            frame.add(this.chooser);
+        JColorChooser chooser = new JColorChooser();
+        JFrame frame = new JFrame(getClass().getName());
+        try {
+            frame.add(chooser);
             frame.setVisible(true);
-        }
-        else if (this.updated) {
-            if (isShowing(this.chooser.getPreviewPanel())) {
-                exit("custom preview panel is showing");
-            }
-            exit(null);
-        }
-        else {
-            Component component = this.chooser.getPreviewPanel();
+            // Check default preview panel
+            setLookAndFeel(UIManager.getInstalledLookAndFeels()[0]);
+            SwingUtilities.updateComponentTreeUI(chooser);
+            Component component = chooser.getPreviewPanel();
             if (component == null) {
-                component = getPreview(this.chooser);
+                component = getPreview(chooser);
             }
             if (!isShowing(component)) {
-                exit("default preview panel is not showing");
+                throw new RuntimeException(
+                        "default preview panel is not showing");
             }
-            this.updated = true;
-            this.chooser.setPreviewPanel(new JPanel());
+            // Check custom preview panel
+            chooser.setPreviewPanel(new JPanel());
+            setLookAndFeel(UIManager.getInstalledLookAndFeels()[1]);
+            SwingUtilities.updateComponentTreeUI(chooser);
+            if (isShowing(chooser.getPreviewPanel())) {
+                throw new RuntimeException("custom preview panel is showing");
+            }
+        } finally {
+            frame.dispose();
         }
-        LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
-        LookAndFeelInfo info = infos[++this.index % infos.length];
+    }
+
+    private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
         try {
-            UIManager.setLookAndFeel(info.getClassName());
+            UIManager.setLookAndFeel(laf.getClassName());
+        } catch (final UnsupportedLookAndFeelException ignored){
+        } catch (ClassNotFoundException | InstantiationException |
+                IllegalAccessException e) {
+            throw new RuntimeException(e);
         }
-        catch (Exception exception) {
-            exit("could not change L&F");
-        }
-        SwingUtilities.updateComponentTreeUI(this.chooser);
-        SwingUtilities.invokeLater(this);
     }
 }
--- a/test/jdk/javax/swing/JTable/6735286/bug6735286.java	Fri Nov 30 13:31:31 2018 +0100
+++ b/test/jdk/javax/swing/JTable/6735286/bug6735286.java	Tue Dec 04 13:09:20 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2018, 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
@@ -24,14 +24,14 @@
 /* @test
    @bug 6735286
    @summary javax.swing.DefaultTableCellRender.getTableCellRendererComponent() doesn't allow passing null Tables
-   @author Pavel Porvatov
 */
 
-import javax.swing.*;
+import javax.swing.JTable;
+import javax.swing.SwingUtilities;
 
 public class bug6735286 {
-    public static void main(String[] args) {
-        SwingUtilities.invokeLater(new Runnable() {
+    public static void main(String[] args) throws Exception {
+        SwingUtilities.invokeAndWait(new Runnable() {
             public void run() {
                 new JTable().getDefaultRenderer(Object.class).getTableCellRendererComponent(null, "a value",
                         true, true, 0, 0);