jdk/test/javax/swing/JTree/6567433/UpdateUIRecursionTest.java
author goetz
Fri, 28 Jul 2017 14:06:28 +0200
changeset 46151 5fa789776f7d
parent 39858 882e63569349
permissions -rw-r--r--
8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests. Summary: Add new keyword 'printer'. Some minor test fixes to show headless exception. Add some @requires windows. Reviewed-by: serb, mbaesken
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39858
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     1
/*
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 39858
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
39858
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     4
 *
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     8
 *
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    13
 * accompanied this code).
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    14
 *
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    18
 *
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    21
 * questions.
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    22
 */
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    23
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 39858
diff changeset
    24
/**
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 39858
diff changeset
    25
 * @test
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 39858
diff changeset
    26
 * @key headful
39858
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    27
 * @bug 6567433
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    28
 *
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    29
 * @summary  JTree.updateUI() invokes updateUI() on its TreeCellrenderer via
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    30
 * SwingUtilities.updateRendererOrEditorUI().
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    31
 * If the TreeCellrenderer is a parent of this JTree, the method recurses
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    32
 * endless.
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    33
 * This test tests that the fix is effective in avoiding recursion.
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    34
 *
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    35
 * @run main/othervm UpdateUIRecursionTest
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    36
 */
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    37
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    38
import java.awt.BorderLayout;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    39
import java.awt.Component;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    40
import javax.swing.JFrame;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    41
import javax.swing.JScrollPane;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    42
import javax.swing.JTree;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    43
import javax.swing.SwingUtilities;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    44
import javax.swing.tree.TreeCellRenderer;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    45
import javax.swing.tree.DefaultTreeCellRenderer;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    46
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    47
public class UpdateUIRecursionTest extends JFrame implements TreeCellRenderer {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    48
    JTree tree;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    49
    DefaultTreeCellRenderer renderer;
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    50
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    51
    public UpdateUIRecursionTest() {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    52
        super("UpdateUIRecursionTest");
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    53
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    54
        setSize(400, 400);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    55
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    56
        String[] listData = {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    57
            "First", "Second", "Third", "Fourth", "Fifth", "Sixth"
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    58
        };
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    59
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    60
        tree = new JTree(listData);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    61
        renderer = new DefaultTreeCellRenderer();
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    62
        getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    63
        tree.setCellRenderer(this);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    64
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    65
        setVisible(true);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    66
    }
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    67
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    68
    public static void main(String[] args) throws Exception {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    69
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    70
        SwingUtilities.invokeAndWait(new Runnable() {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    71
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    72
            @Override
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    73
            public void run() {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    74
                UpdateUIRecursionTest obj = new UpdateUIRecursionTest();
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    75
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    76
                obj.test();
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    77
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    78
                obj.disposeUI();
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    79
            }
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    80
        });
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    81
    }
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    82
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    83
    public void test() {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    84
        tree.updateUI();
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    85
    }
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    86
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    87
    public void disposeUI() {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    88
        setVisible(false);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    89
        dispose();
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    90
    }
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    91
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    92
    @Override
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    93
    public Component getTreeCellRendererComponent(JTree tree, Object value,
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    94
                              boolean selected, boolean expanded, boolean leaf,
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    95
                              int row, boolean hasFocus)
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    96
    {
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    97
        return renderer.getTreeCellRendererComponent(tree, value, leaf,
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    98
                                                expanded, leaf, row, hasFocus);
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
    99
    }
882e63569349 6567433: JComponent.updateUI() may create StackOverflowError
aghaisas
parents:
diff changeset
   100
}