Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/RepaintManager/7013453/bug7013453.java
38853 views
/*1* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 701345325@summary BufferStrategyPaintManager.dispose will cause IllegalMonitorStateException in event thread26@author Pavel Porvatov27*/2829import javax.swing.*;30import java.lang.reflect.Field;31import java.lang.reflect.InvocationTargetException;32import java.lang.reflect.Method;3334public class bug7013453 {35public static void main(String[] args) throws Exception {36SwingUtilities.invokeAndWait(new Runnable() {37public void run() {38try {39Method getPaintManagerMethod = RepaintManager.class.getDeclaredMethod("getPaintManager");4041getPaintManagerMethod.setAccessible(true);4243final Object paintManager = getPaintManagerMethod.invoke(RepaintManager.currentManager(new JLabel()));4445String paintManagerName = paintManager.getClass().getCanonicalName();4647if (!paintManagerName.equals("javax.swing.BufferStrategyPaintManager")) {48System.out.println("The test is not suitable for the " + paintManagerName +49" paint manager. The test skipped.");5051return;52}5354final Field showingField = paintManager.getClass().getDeclaredField("showing");5556showingField.setAccessible(true);5758synchronized (paintManager) {59showingField.setBoolean(paintManager, true);60}6162// Postpone reset the showing field63Thread thread = new Thread(new Runnable() {64public void run() {65try {66Thread.sleep(500);67} catch (InterruptedException e) {68throw new RuntimeException(e);69}7071synchronized (paintManager) {72try {73showingField.setBoolean(paintManager, false);74} catch (IllegalAccessException e) {75throw new RuntimeException(e);76}77}78}79});8081thread.start();8283Method disposeMethod = paintManager.getClass().getDeclaredMethod("dispose");8485disposeMethod.setAccessible(true);8687disposeMethod.invoke(paintManager);8889System.out.println("The test passed.");90} catch (NoSuchMethodException e) {91throw new RuntimeException(e);92} catch (InvocationTargetException e) {93throw new RuntimeException(e);94} catch (IllegalAccessException e) {95throw new RuntimeException(e);96} catch (NoSuchFieldException e) {97throw new RuntimeException(e);98}99}100});101}102}103104105