< prev index next >

test/jdk/tools/launcher/modules/illegalaccess/IllegalAccessTest.java

Print this page


   1 /*
   2  * Copyright (c) 2017, 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  * @requires vm.compMode != "Xcomp"
  27  * @modules java.base/jdk.internal.misc
  28  *          java.base/sun.security.x509
  29  *          java.activation
  30  * @library /test/lib /lib/testlibrary modules
  31  * @build IllegalAccessTest TryAccess JarUtils
  32  *        jdk.test.lib.compiler.CompilerUtils
  33  *        jdk.testlibrary.*
  34  * @build m/*
  35  * @run testng/othervm/timeout=180 IllegalAccessTest
  36  * @summary Basic test for java --illegal-access=$VALUE
  37  */
  38 
  39 import java.nio.file.Files;
  40 import java.nio.file.Path;
  41 import java.nio.file.Paths;
  42 import java.util.ArrayList;
  43 import java.util.List;
  44 import java.util.jar.Attributes;
  45 import java.util.jar.Manifest;
  46 import java.util.stream.Stream;
  47 
  48 import jdk.test.lib.compiler.CompilerUtils;
  49 import jdk.testlibrary.ProcessTools;


 250 
 251     @Test(dataProvider = "permitCases")
 252     public void testPermit(String action, Result expectedResult) throws Exception {
 253         run(action, expectedResult, "--illegal-access=permit");
 254     }
 255 
 256     @Test(dataProvider = "permitCases")
 257     public void testWarn(String action, Result expectedResult) throws Exception {
 258         run(action, expectedResult, "--illegal-access=warn");
 259     }
 260 
 261     @Test(dataProvider = "permitCases")
 262     public void testDebug(String action, Result expectedResult) throws Exception {
 263         // expect stack trace with WARNING
 264         if (expectedResult.expectedOutput().anyMatch("WARNING"::equals)) {
 265             expectedResult.expect("TryAccess.main");
 266         }
 267         run(action, expectedResult, "--illegal-access=debug");
 268     }
 269 
 270     /**
 271      * Test accessing internals of upgradeable module
 272      */
 273     public void testWithUpgradedModule() throws Exception {
 274         // upgradeable module loaded from run-time image
 275         run("setAccessibleNotPublicMemberUpgradeableModule", successWithWarning(),
 276                 "--add-modules=java.activation");
 277 
 278         // upgradeable module loaded from upgrade module path
 279         Path upgradesrc = Paths.get(TEST_SRC, "upgradesrc");
 280         Path upgrademods = Files.createDirectory(Paths.get("upgrademods"));
 281         Path output = upgrademods.resolve("java.activation");
 282         assertTrue(CompilerUtils.compile(upgradesrc, output));
 283         run("setAccessibleNotPublicMemberUpgradeableModule",
 284                 fail("InaccessibleObjectException"),
 285                 "--upgrade-module-path=" + upgrademods,
 286                 "--add-modules=java.activation");
 287     }
 288 
 289     /**
 290      * Specify --add-exports to export a package
 291      */
 292     public void testWithAddExportsOption() throws Exception {
 293         // warning
 294         run("reflectPublicMemberNonExportedPackage", successWithWarning());
 295 
 296         // no warning due to --add-exports
 297         run("reflectPublicMemberNonExportedPackage", successNoWarning(),
 298                 "--add-exports", "java.base/sun.security.x509=ALL-UNNAMED");
 299 
 300         // attempt two illegal accesses, one allowed by --add-exports
 301         run("reflectPublicMemberNonExportedPackage"
 302                 + ",setAccessibleNonPublicMemberExportedPackage",
 303             successWithWarning(),
 304             "--add-exports", "java.base/sun.security.x509=ALL-UNNAMED");
 305     }
 306 
 307     /**


   1 /*
   2  * Copyright (c) 2017, 2018, 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  * @requires vm.compMode != "Xcomp"
  27  * @modules java.base/jdk.internal.misc
  28  *          java.base/sun.security.x509

  29  * @library /test/lib /lib/testlibrary modules
  30  * @build IllegalAccessTest TryAccess JarUtils
  31  *        jdk.test.lib.compiler.CompilerUtils
  32  *        jdk.testlibrary.*
  33  * @build m/*
  34  * @run testng/othervm/timeout=180 IllegalAccessTest
  35  * @summary Basic test for java --illegal-access=$VALUE
  36  */
  37 
  38 import java.nio.file.Files;
  39 import java.nio.file.Path;
  40 import java.nio.file.Paths;
  41 import java.util.ArrayList;
  42 import java.util.List;
  43 import java.util.jar.Attributes;
  44 import java.util.jar.Manifest;
  45 import java.util.stream.Stream;
  46 
  47 import jdk.test.lib.compiler.CompilerUtils;
  48 import jdk.testlibrary.ProcessTools;


 249 
 250     @Test(dataProvider = "permitCases")
 251     public void testPermit(String action, Result expectedResult) throws Exception {
 252         run(action, expectedResult, "--illegal-access=permit");
 253     }
 254 
 255     @Test(dataProvider = "permitCases")
 256     public void testWarn(String action, Result expectedResult) throws Exception {
 257         run(action, expectedResult, "--illegal-access=warn");
 258     }
 259 
 260     @Test(dataProvider = "permitCases")
 261     public void testDebug(String action, Result expectedResult) throws Exception {
 262         // expect stack trace with WARNING
 263         if (expectedResult.expectedOutput().anyMatch("WARNING"::equals)) {
 264             expectedResult.expect("TryAccess.main");
 265         }
 266         run(action, expectedResult, "--illegal-access=debug");
 267     }
 268 


















 269 
 270     /**
 271      * Specify --add-exports to export a package
 272      */
 273     public void testWithAddExportsOption() throws Exception {
 274         // warning
 275         run("reflectPublicMemberNonExportedPackage", successWithWarning());
 276 
 277         // no warning due to --add-exports
 278         run("reflectPublicMemberNonExportedPackage", successNoWarning(),
 279                 "--add-exports", "java.base/sun.security.x509=ALL-UNNAMED");
 280 
 281         // attempt two illegal accesses, one allowed by --add-exports
 282         run("reflectPublicMemberNonExportedPackage"
 283                 + ",setAccessibleNonPublicMemberExportedPackage",
 284             successWithWarning(),
 285             "--add-exports", "java.base/sun.security.x509=ALL-UNNAMED");
 286     }
 287 
 288     /**


< prev index next >