jdk/test/java/awt/Focus/SortingFPT/JDK8048887.java
author ssadetsky
Fri, 02 Sep 2016 10:31:49 +0300
changeset 40995 c096d4be5b5e
parent 27049 083369e8f426
permissions -rw-r--r--
8164937: Remove code from SortingFocusTraversalPolicy that hacks into non-public Arrays.legacyMergeSort Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25570
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     1
/*
40995
c096d4be5b5e 8164937: Remove code from SortingFocusTraversalPolicy that hacks into non-public Arrays.legacyMergeSort
ssadetsky
parents: 27049
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
25570
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     4
 *
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     8
 *
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    13
 * accompanied this code).
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    14
 *
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    18
 *
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    21
 * questions.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    22
 */
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    23
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    24
/*
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    25
  @test
40995
c096d4be5b5e 8164937: Remove code from SortingFocusTraversalPolicy that hacks into non-public Arrays.legacyMergeSort
ssadetsky
parents: 27049
diff changeset
    26
  @bug       8048887 8164937
25570
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    27
  @summary   Tests SortingFTP for an exception caused by the tim-sort algo.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    28
  @author    anton.tarasov: area=awt.focus
27049
083369e8f426 8049346: [TESTBUG] fix the @run line of the test: jdk/test/java/awt/Focus/SortingFTP/JDK8048887.java
ant
parents: 25570
diff changeset
    29
  @run       main JDK8048887
25570
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    30
*/
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    31
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    32
import javax.swing.JFrame;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    33
import javax.swing.JPanel;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    34
import javax.swing.SwingUtilities;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    35
import java.awt.Dimension;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    36
import java.awt.Color;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    37
import java.awt.GridBagLayout;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    38
import java.awt.GridBagConstraints;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    39
import java.awt.event.WindowAdapter;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    40
import java.awt.event.WindowEvent;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    41
import java.util.concurrent.CountDownLatch;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    42
import java.util.concurrent.TimeUnit;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    43
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    44
public class JDK8048887 {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    45
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    46
    static volatile boolean passed = true;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    47
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    48
    public static void main(String[] args) {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    49
        JDK8048887 app = new JDK8048887();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    50
        app.start();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    51
    }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    52
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    53
    public void start() {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    54
        final CountDownLatch latch = new CountDownLatch(1);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    55
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    56
        SwingUtilities.invokeLater(() -> {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    57
                // Catch the original exception which sounds like:
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    58
                // java.lang.IllegalArgumentException: Comparison method violates its general contract!
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    59
                Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    60
                        public void uncaughtException(Thread t, Throwable e) {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    61
                            e.printStackTrace();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    62
                            if (e instanceof IllegalArgumentException) {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    63
                                passed = false;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    64
                                latch.countDown();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    65
                            }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    66
                        }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    67
                    });
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    68
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    69
                TestDialog d = new TestDialog();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    70
                // It's expected that the dialog is focused on start.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    71
                // The listener is called after the FTP completes processing and the bug is reproduced or not.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    72
                d.addWindowFocusListener(new WindowAdapter() {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    73
                        public void windowGainedFocus(WindowEvent e) {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    74
                            latch.countDown();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    75
                        }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    76
                });
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    77
                d.setVisible(true);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    78
        });
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    79
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    80
        try {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    81
            latch.await(5, TimeUnit.SECONDS);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    82
        } catch (InterruptedException e) {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    83
            e.printStackTrace();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    84
        }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    85
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    86
        if (passed)
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    87
            System.out.println("Test passed.");
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    88
        else
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    89
            throw new RuntimeException("Test failed!");
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    90
    }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    91
}
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    92
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    93
class TestDialog extends JFrame {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    94
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    95
    // The layout of the components reproduces the transitivity issue
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    96
    // with SortingFocusTraversalPolicy relying on the tim-sort algo.
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    97
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    98
    private static int[] Xs = new int[] {71, 23, 62, 4, 79, 39, 34, 9, 84, 58, 30, 34, 38, 15, 69, 10, 44, 95, 70, 54,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
    99
    44, 62, 77, 64, 70, 83, 31, 48, 96, 54, 40, 3, 60, 58, 3, 20, 94, 54, 26, 19, 48, 47, 12, 70, 86, 43, 71, 97, 19,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   100
    69, 90, 22, 43, 76, 10, 60, 29, 49, 9, 9, 15, 73, 85, 80, 81, 35, 87, 43, 17, 57, 38, 44, 29, 86, 96, 15, 57, 26,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   101
    27, 78, 26, 87, 43, 6, 4, 16, 57, 99, 32, 86, 96, 5, 50, 69, 12, 4, 36, 84, 71, 60, 22, 46, 11, 44, 87, 3, 23, 14,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   102
    43, 25, 32, 44, 11, 18, 77, 2, 51, 87, 88, 53, 69, 37, 14, 10, 25, 73, 39, 33, 91, 51, 96, 9, 74, 66, 70, 42, 72,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   103
    7, 82, 40, 91, 33, 83, 54, 33, 50, 83, 1, 81, 32, 66, 11, 75, 56, 53, 45, 1, 69, 46, 31, 79, 58, 12, 20, 92, 49,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   104
    50, 90, 33, 8, 43, 93, 72, 78, 9, 56, 84, 60, 30, 39, 33, 88, 84, 56, 49, 47, 4, 90, 57, 6, 23, 96, 37, 88, 22, 79,
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   105
    35, 80, 45, 55};
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   106
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   107
    public TestDialog() {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   108
        JPanel panel = new JPanel(new GridBagLayout());
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   109
        GridBagConstraints gbc = new GridBagConstraints();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   110
        for (int i=0; i < Xs.length; i++) {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   111
            gbc.gridx = Xs[i];
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   112
            gbc.gridy = 100 - gbc.gridx;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   113
            panel.add(new MyComponent(), gbc);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   114
        }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   115
        getRootPane().getContentPane().add(panel);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   116
        pack();
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   117
    }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   118
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   119
    public static class MyComponent extends JPanel {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   120
        private final static Dimension SIZE = new Dimension(1,1);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   121
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   122
        public MyComponent() {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   123
            setBackground(Color.BLACK);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   124
            setOpaque(true);
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   125
        }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   126
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   127
        @Override
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   128
        public Dimension getPreferredSize() {
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   129
            return SIZE;
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   130
        }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   131
    }
a72022403893 8048887: SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method
ant
parents:
diff changeset
   132
}