Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/Security/6657138/bug6657138.java
38854 views
/*1* Copyright (c) 2009, 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/*24* @test25* @bug 665713826* @summary Verifies that buttons and labels don't share their ui's across appContexts27* @author Alexander Potochkin28*/2930import sun.awt.SunToolkit;3132import javax.swing.*;33import javax.swing.plaf.ButtonUI;34import javax.swing.plaf.ComponentUI;35import java.util.Collections;36import java.util.HashMap;37import java.util.Map;38import java.util.Set;3940public class bug6657138 implements Runnable {4142private static Map<JComponent, Map<String, ComponentUI>> componentMap =43Collections.synchronizedMap(44new HashMap<JComponent, Map<String, ComponentUI>>());4546public void run() {47SunToolkit.createNewAppContext();48try {49testUIMap();50} catch (Exception e) {51throw new RuntimeException(e);52}53}5455private static void testUIMap() throws Exception {56UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();57Set<JComponent> components = componentMap.keySet();58for (JComponent c : components) {59Map<String, ComponentUI> uiMap = componentMap.get(c);6061for (UIManager.LookAndFeelInfo laf : lafs) {62if ("Nimbus".equals(laf.getName())) {63// for some unclear reasons64// Nimbus ui delegate for a button is null65// when this method is called from the new AppContext66continue;67}68String className = laf.getClassName();69UIManager.setLookAndFeel(className);70ComponentUI ui = UIManager.getUI(c);71if (ui == null) {72throw new RuntimeException("UI is null for " + c);73}74if (ui == uiMap.get(laf.getName())) {75throw new RuntimeException(76"Two AppContexts share the same UI delegate! \n" +77c + "\n" + ui);78}79uiMap.put(laf.getName(), ui);80}81}82}8384public static void main(String[] args) throws Exception {85componentMap.put(new JButton("JButton"),86new HashMap<String, ComponentUI>());87componentMap.put(new JToggleButton("JToggleButton"),88new HashMap<String, ComponentUI>());89componentMap.put(new JRadioButton("JRadioButton"),90new HashMap<String, ComponentUI>());91componentMap.put(new JCheckBox("JCheckBox"),92new HashMap<String, ComponentUI>());93componentMap.put(new JCheckBox("JLabel"),94new HashMap<String, ComponentUI>());95testUIMap();96ThreadGroup group = new ThreadGroup("6657138");97Thread thread = new Thread(group, new bug6657138());98thread.start();99thread.join();100}101}102103104105