jdk/test/javax/swing/RepaintManager/7013453/bug7013453.java
author rupashka
Thu, 03 Feb 2011 16:30:51 +0300
changeset 8145 6714ca3d6773
child 42338 a60f280f803c
permissions -rw-r--r--
7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread Reviewed-by: alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8145
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     1
/*
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     4
 *
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     8
 *
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    13
 * accompanied this code).
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    14
 *
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    18
 *
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    21
 * questions.
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    22
 */
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    23
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    24
/* @test
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    25
   @bug 7013453
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    26
   @summary BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    27
   @author Pavel Porvatov
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    28
*/
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    29
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    30
import javax.swing.*;
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    31
import java.lang.reflect.Field;
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    32
import java.lang.reflect.InvocationTargetException;
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    33
import java.lang.reflect.Method;
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    34
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    35
public class bug7013453 {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    36
    public static void main(String[] args) throws Exception {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    37
        SwingUtilities.invokeAndWait(new Runnable() {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    38
            public void run() {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    39
                try {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    40
                    Method getPaintManagerMethod = RepaintManager.class.getDeclaredMethod("getPaintManager");
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    41
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    42
                    getPaintManagerMethod.setAccessible(true);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    43
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    44
                    final Object paintManager = getPaintManagerMethod.invoke(RepaintManager.currentManager(new JLabel()));
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    45
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    46
                    String paintManagerName = paintManager.getClass().getCanonicalName();
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    47
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    48
                    if (!paintManagerName.equals("javax.swing.BufferStrategyPaintManager")) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    49
                        System.out.println("The test is not suitable for the " + paintManagerName +
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    50
                                " paint manager. The test skipped.");
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    51
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    52
                        return;
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    53
                    }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    54
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    55
                    final Field showingField = paintManager.getClass().getDeclaredField("showing");
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    56
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    57
                    showingField.setAccessible(true);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    58
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    59
                    synchronized (paintManager) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    60
                        showingField.setBoolean(paintManager, true);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    61
                    }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    62
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    63
                    // Postpone reset the showing field
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    64
                    Thread thread = new Thread(new Runnable() {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    65
                        public void run() {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    66
                            try {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    67
                                Thread.sleep(500);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    68
                            } catch (InterruptedException e) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    69
                                throw new RuntimeException(e);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    70
                            }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    71
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    72
                            synchronized (paintManager) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    73
                                try {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    74
                                    showingField.setBoolean(paintManager, false);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    75
                                } catch (IllegalAccessException e) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    76
                                    throw new RuntimeException(e);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    77
                                }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    78
                            }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    79
                        }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    80
                    });
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    81
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    82
                    thread.start();
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    83
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    84
                    Method disposeMethod = paintManager.getClass().getDeclaredMethod("dispose");
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    85
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    86
                    disposeMethod.setAccessible(true);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    87
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    88
                    disposeMethod.invoke(paintManager);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    89
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    90
                    System.out.println("The test passed.");
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    91
                } catch (NoSuchMethodException e) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    92
                    throw new RuntimeException(e);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    93
                } catch (InvocationTargetException e) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    94
                    throw new RuntimeException(e);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    95
                } catch (IllegalAccessException e) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    96
                    throw new RuntimeException(e);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    97
                } catch (NoSuchFieldException e) {
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    98
                    throw new RuntimeException(e);
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
    99
                }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
   100
            }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
   101
        });
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
   102
    }
6714ca3d6773 7013453: BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread
rupashka
parents:
diff changeset
   103
}