--- old/test/hotspot/jtreg/runtime/cds/appcds/PackageSealing.java 2020-06-24 22:02:43.303441772 +0000 +++ new/test/hotspot/jtreg/runtime/cds/appcds/PackageSealing.java 2020-06-24 22:02:42.377419184 +0000 @@ -29,6 +29,7 @@ * @library /test/lib * @compile test-classes/C1.java * @compile test-classes/C2.java + * @compile test-classes/C3.java * @compile test-classes/PackageSealingTest.java * @compile test-classes/Hello.java * @run driver PackageSealing @@ -50,13 +51,31 @@ // test shared package from -cp path TestCommon.testDump(jars, TestCommon.list(classList)); OutputAnalyzer output; - output = TestCommon.exec(jars, "PackageSealingTest"); + output = TestCommon.exec(jars, "PackageSealingTest", + "sealed/pkg/C1", "sealed", "pkg/C2", "notSealed"); TestCommon.checkExec(output, "OK"); // test shared package from -Xbootclasspath/a TestCommon.dump(helloJar, TestCommon.list(classList), "-Xbootclasspath/a:" + appJar); - output = TestCommon.exec(helloJar, "-Xbootclasspath/a:" + appJar, "PackageSealingTest"); + output = TestCommon.exec(helloJar, "-Xbootclasspath/a:" + appJar, + "PackageSealingTest", + "sealed/pkg/C1", "sealed", "pkg/C2", "notSealed"); TestCommon.checkExec(output, "OK"); + + // Test loading of two classes from the same package from different jars. + // First loaded class is from a non-sealed package, the second loaded + // class is from the same package but sealed. + // The expected result is a SecurityException with a "sealing violation". + classList[1] = "sealed/pkg/C3"; // C3 is from a non-sealed package + String[] classList2 = {"sealed/pkg/C3", "sealed/pkg/C1", "PackageSealingTest"}; + String nonSealedJar = ClassFileInstaller.writeJar("non_sealed.jar", "sealed/pkg/C3"); + jars = helloJar + File.pathSeparator + nonSealedJar; + TestCommon.testDump(jars, TestCommon.list(classList2), "-XX:+TraceExceptions"); + jars += File.pathSeparator + appJar; + output = TestCommon.exec(jars, "PackageSealingTest", + "sealed/pkg/C3", "notSealed", "sealed/pkg/C1", "sealed"); + TestCommon.checkExec(output, "sealing violation: can't seal package sealed.pkg: already defined"); + } }