1 /*
   2  * Copyright (c) 2015, 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  * @bug 8051626
  27  * @summary Ensure no failure when using Java Accessibility Utility with security manager
  28  *
  29  * @run main/othervm/secure=java.lang.SecurityManager/java.security.policy=jtreg.security.policy Bug8051626 
  30  */
  31 
  32 import com.sun.java.accessibility.util.AWTEventMonitor;
  33 import java.awt.Dimension;
  34 import java.util.logging.Level;
  35 import java.util.logging.Logger;
  36 import javax.swing.JButton;
  37 import javax.swing.JFrame;
  38 import javax.swing.JPanel;
  39 
  40 public class Bug8051626 {
  41 
  42     public static void main(final String[] args) {
  43             final Bug8051626 app = new Bug8051626();
  44             app.test();
  45         }
  46 
  47     private void test() {
  48         final JFrame frame = new JFrame("Bug 8051626");
  49         final JPanel panel = new JPanel();
  50         final JButton okButton = new JButton("OK");
  51         panel.add(okButton);
  52         frame.getContentPane().add(panel);
  53         frame.setMinimumSize(new Dimension(300, 180));
  54         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  55         frame.pack();
  56         frame.setLocation(400, 300);
  57         frame.setVisible(true);
  58         try {
  59             Thread.sleep(1000);
  60         } catch (InterruptedException ex) {
  61             // ignore
  62         }
  63         // If the security manager is on this should not cause an exception.
  64         // Prior to the 8051626 fix it would as follows:
  65         // java.security.AccessControlException:
  66         //   access denied ("java.lang.RuntimePermission" "accessClassInPackage.com.sun.java.accessibility.util")
  67         try {
  68             AWTEventMonitor.getComponentWithFocus();
  69         } catch (Exception e) {
  70             System.out.println("\nException: " + e);
  71             System.exit(1);
  72         }
  73     }
  74 
  75 }