< prev index next >
test/hotspot/jtreg/runtime/cds/appcds/PackageSealing.java
Print this page
@@ -27,10 +27,11 @@
* @summary AppCDS handling of package.
* @requires vm.cds
* @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
*/
@@ -48,15 +49,33 @@
String jars = helloJar + File.pathSeparator + appJar;
// 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");
+
}
}
< prev index next >