Path: blob/master/test/jdk/java/beans/EventHandler/Test6277266.java
41149 views
/*1* Copyright (c) 2005, 2012, 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 627726626* @summary Tests access control issue in EventHandler27* @run main/othervm -Djava.security.manager=allow Test627726628* @author Jeff Nisewanger29*/3031import java.beans.EventHandler;32import java.lang.reflect.InvocationTargetException;33import java.lang.reflect.Proxy;34import javax.swing.SwingUtilities;3536public class Test6277266 {37public static void main(String[] args) {38System.setSecurityManager(new SecurityManager());39try {40SwingUtilities.invokeAndWait(41(Runnable) Proxy.newProxyInstance(42null,43new Class[] {Runnable.class},44new EventHandler(45Test6277266.class,46"getProtectionDomain",47null,48null49)50)51);52throw new Error("SecurityException expected");53} catch (SecurityException exception) {54return; // expected security exception in JDK 755} catch (InvocationTargetException exception) {56if (exception.getCause() instanceof SecurityException){57return; // expected security exception in JDK 858}59throw new Error("unexpected exception", exception);60} catch (InterruptedException exception) {61throw new Error("unexpected exception", exception);62}63}64}656667