Path: blob/master/test/jdk/com/sun/java/accessibility/util/8051626/Bug8051626.java
41161 views
/*1* Copyright (c) 2015, 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* @key headful26* @bug 805162627* @summary Ensure no failure when using Java Accessibility Utility with security manager28* @modules java.desktop jdk.accessibility29*30* @run main/othervm -Djava.security.manager=allow Bug805162631*/3233import com.sun.java.accessibility.util.AWTEventMonitor;34import java.awt.Dimension;35import java.lang.reflect.InvocationTargetException;36import javax.swing.JButton;37import javax.swing.JFrame;38import javax.swing.JPanel;39import javax.swing.SwingUtilities;4041public class Bug8051626 {4243public static void main(final String[] args) throws InterruptedException,44InvocationTargetException {45final Bug8051626 app = new Bug8051626();46app.test();47}4849private void test() throws InterruptedException, InvocationTargetException {50System.setSecurityManager(new SecurityManager());51SwingUtilities.invokeAndWait(new Runnable() {52@Override53public void run() {54final JFrame frame = new JFrame("Bug 8051626");55try {56final JPanel panel = new JPanel();57final JButton okButton = new JButton("OK");58panel.add(okButton);59frame.getContentPane().add(panel);60frame.setMinimumSize(new Dimension(300, 180));61frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);62frame.pack();63frame.setLocation(400, 300);64frame.setVisible(true);65// If the security manager is on this should not cause an exception.66// Prior to the 8051626 fix it would as follows:67// java.security.AccessControlException:68// access denied ("java.lang.RuntimePermission" "accessClassInPackage.com.sun.java.accessibility.util")69AWTEventMonitor.getComponentWithFocus();70} finally {71frame.dispose();72}73}74});75}7677}787980