Bug8051626.java revision 12640:8164bc5dd95e
155682Smarkm/* 278527Sassar * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 355682Smarkm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 455682Smarkm * 555682Smarkm * This code is free software; you can redistribute it and/or modify it 655682Smarkm * under the terms of the GNU General Public License version 2 only, as 755682Smarkm * published by the Free Software Foundation. 855682Smarkm * 955682Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT 1055682Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1155682Smarkm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1255682Smarkm * version 2 for more details (a copy is included in the LICENSE file that 1355682Smarkm * accompanied this code). 1455682Smarkm * 1555682Smarkm * You should have received a copy of the GNU General Public License version 1655682Smarkm * 2 along with this work; if not, write to the Free Software Foundation, 1755682Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1855682Smarkm * 1955682Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2055682Smarkm * or visit www.oracle.com if you need additional information or have any 2155682Smarkm * questions. 2255682Smarkm */ 2355682Smarkm 2455682Smarkm/* 2555682Smarkm * @test 2655682Smarkm * @bug 8051626 2755682Smarkm * @summary Ensure no failure when using Java Accessibility Utility with security manager 2855682Smarkm * @modules java.desktop jdk.accessibility 2955682Smarkm * 3055682Smarkm * @run main/othervm Bug8051626 3155682Smarkm */ 3255682Smarkm 3355682Smarkmimport com.sun.java.accessibility.util.AWTEventMonitor; 3455682Smarkmimport java.awt.Dimension; 3555682Smarkmimport java.lang.reflect.InvocationTargetException; 36178825Sdfrimport javax.swing.JButton; 3755682Smarkmimport javax.swing.JFrame; 38178825Sdfrimport javax.swing.JPanel; 3955682Smarkmimport javax.swing.SwingUtilities; 4055682Smarkm 4155682Smarkmpublic class Bug8051626 { 4255682Smarkm 4355682Smarkm public static void main(final String[] args) throws InterruptedException, 44178825Sdfr InvocationTargetException { 45178825Sdfr final Bug8051626 app = new Bug8051626(); 46178825Sdfr app.test(); 47178825Sdfr } 48178825Sdfr 4955682Smarkm private void test() throws InterruptedException, InvocationTargetException { 50178825Sdfr System.setSecurityManager(new SecurityManager()); 51178825Sdfr SwingUtilities.invokeAndWait(new Runnable() { 5255682Smarkm @Override 53178825Sdfr public void run() { 54178825Sdfr final JFrame frame = new JFrame("Bug 8051626"); 55178825Sdfr try { 56178825Sdfr final JPanel panel = new JPanel(); 57178825Sdfr final JButton okButton = new JButton("OK"); 58178825Sdfr panel.add(okButton); 59178825Sdfr frame.getContentPane().add(panel); 60178825Sdfr frame.setMinimumSize(new Dimension(300, 180)); 61178825Sdfr frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 62178825Sdfr frame.pack(); 63178825Sdfr frame.setLocation(400, 300); 64178825Sdfr frame.setVisible(true); 65178825Sdfr // If the security manager is on this should not cause an exception. 6655682Smarkm // Prior to the 8051626 fix it would as follows: 67178825Sdfr // java.security.AccessControlException: 68178825Sdfr // access denied ("java.lang.RuntimePermission" "accessClassInPackage.com.sun.java.accessibility.util") 69178825Sdfr AWTEventMonitor.getComponentWithFocus(); 70178825Sdfr } finally { 71178825Sdfr frame.dispose(); 72178825Sdfr } 73178825Sdfr } 74178825Sdfr }); 75178825Sdfr } 76178825Sdfr 77178825Sdfr} 7855682Smarkm