Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/lang/invoke/lambda/LambdaAccessControlDoPrivilegedTest.java
48795 views
/*1* Copyright (c) 2012, 2013, 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 800388126* @summary tests DoPrivileged action (implemented as lambda expressions) by27* inserting them into the BootClassPath.28* @compile -XDignore.symbol.file LambdaAccessControlDoPrivilegedTest.java LUtils.java29* @run main/othervm LambdaAccessControlDoPrivilegedTest30*/31import java.io.File;32import java.util.ArrayList;33import java.util.List;3435public class LambdaAccessControlDoPrivilegedTest extends LUtils {36public static void main(String... args) {37final List<String> scratch = new ArrayList();38scratch.clear();39scratch.add("import java.security.*;");40scratch.add("public class DoPriv {");41scratch.add("public static void main(String... args) {");42scratch.add("String prop = AccessController.doPrivileged((PrivilegedAction<String>) () -> {");43scratch.add("return System.getProperty(\"user.home\");");44scratch.add("});");45scratch.add("}");46scratch.add("}");47File doprivJava = new File("DoPriv.java");48File doprivClass = getClassFile(doprivJava);49createFile(doprivJava, scratch);5051scratch.clear();52scratch.add("public class Bar {");53scratch.add("public static void main(String... args) {");54scratch.add("System.out.println(\"sun.boot.class.path\" + \"=\" +");55scratch.add(" System.getProperty(\"sun.boot.class.path\", \"\"));");56scratch.add("System.setSecurityManager(new SecurityManager());");57scratch.add("DoPriv.main();");58scratch.add("}");59scratch.add("}");6061File barJava = new File("Bar.java");62File barClass = getClassFile(barJava);63createFile(barJava, scratch);6465String[] javacArgs = {barJava.getName(), doprivJava.getName()};66compile(javacArgs);67File jarFile = new File("foo.jar");68String[] jargs = {"cvf", jarFile.getName(), doprivClass.getName()};69jarTool.run(jargs);70doprivJava.delete();71doprivClass.delete();72TestResult tr = doExec(JAVA_CMD.getAbsolutePath(),73"-Xbootclasspath/p:foo.jar",74"-cp", ".", "Bar");75tr.assertZero("testDoPrivileged fails");76barJava.delete();77barClass.delete();78jarFile.delete();79}80}818283