Test6660049.java revision 14851:980da45565c8
1/* 2 * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @key headful 27 * @bug 6660049 6849518 28 * @summary Tests the Region initialization 29 * @author Sergey Malenkov 30 * @modules java.desktop/sun.awt 31 */ 32 33import sun.awt.SunToolkit; 34 35import javax.swing.JButton; 36import javax.swing.JComponent; 37import javax.swing.SwingUtilities; 38import javax.swing.plaf.synth.Region; 39import javax.swing.plaf.synth.SynthLookAndFeel; 40 41public class Test6660049 implements Runnable { 42 public static void main(String[] args) { 43 SwingUtilities.invokeLater(new Test6660049( 44 javax.swing.JButton.class, 45 javax.swing.JCheckBox.class, 46 javax.swing.JCheckBoxMenuItem.class, 47 javax.swing.JColorChooser.class, 48 javax.swing.JComboBox.class, 49 javax.swing.JDesktopPane.class, 50 javax.swing.JEditorPane.class, 51 javax.swing.JFileChooser.class, 52 javax.swing.JFormattedTextField.class, 53 javax.swing.JInternalFrame.class, 54 javax.swing.JLabel.class, 55 javax.swing.JList.class, 56 javax.swing.JMenu.class, 57 javax.swing.JMenuBar.class, 58 javax.swing.JMenuItem.class, 59 javax.swing.JOptionPane.class, 60 javax.swing.JPanel.class, 61 javax.swing.JPasswordField.class, 62 javax.swing.JPopupMenu.class, 63 javax.swing.JProgressBar.class, 64 javax.swing.JRadioButton.class, 65 javax.swing.JRadioButtonMenuItem.class, 66 javax.swing.JRootPane.class, 67 javax.swing.JScrollBar.class, 68 javax.swing.JScrollPane.class, 69 javax.swing.JSeparator.class, 70 javax.swing.JSlider.class, 71 javax.swing.JSpinner.class, 72 javax.swing.JSplitPane.class, 73 javax.swing.JTabbedPane.class, 74 javax.swing.JTable.class, 75 javax.swing.JTextArea.class, 76 javax.swing.JTextField.class, 77 javax.swing.JTextPane.class, 78 javax.swing.JToggleButton.class, 79 javax.swing.JToolBar.class, 80 javax.swing.JToolTip.class, 81 javax.swing.JTree.class, 82 javax.swing.JViewport.class, 83 javax.swing.table.JTableHeader.class)); 84 } 85 86 private final Class<? extends JComponent>[] types; 87 private final Region region; 88 89 private Test6660049(Class<? extends JComponent>... types) { 90 this.types = types; 91 run(); 92 93 this.region = new Region("Button", "ButtonUI", true) { 94 @Override 95 public String getName() { 96 throw new Error("6660049: exploit is available"); 97 } 98 }; 99 } 100 101 public void run() { 102 if (this.region != null) { 103 SunToolkit.createNewAppContext(); 104 } 105 for (Class<? extends JComponent> type : this.types) { 106 Region region = getRegion(type); 107 if (region == null) { 108 throw new Error("6849518: region is not initialized"); 109 } 110 } 111 getRegion(JButton.class).getName(); 112 } 113 114 private static Region getRegion(Class<? extends JComponent> type) { 115 try { 116 return SynthLookAndFeel.getRegion(type.newInstance()); 117 } 118 catch (IllegalAccessException exception) { 119 throw new Error("unexpected exception", exception); 120 } 121 catch (InstantiationException exception) { 122 throw new Error("unexpected exception", exception); 123 } 124 } 125} 126