< prev index next >

test/hotspot/jtreg/runtime/appcds/BootClassPathMismatch.java

Print this page

        

@@ -32,10 +32,12 @@
  *          jdk.jartool/sun.tools.jar
  * @compile test-classes/Hello.java
  * @run main BootClassPathMismatch
  */
 
+import jdk.test.lib.cds.CDSOptions;
+import jdk.test.lib.cds.CDSTestUtils;
 import jdk.test.lib.process.OutputAnalyzer;
 import java.io.File;
 import java.nio.file.Files;
 import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.StandardCopyOption;

@@ -50,14 +52,17 @@
         copyHelloToNewDir();
 
         BootClassPathMismatch test = new BootClassPathMismatch();
         test.testBootClassPathMismatch();
         test.testBootClassPathMismatch2();
+        test.testBootClassPathMismatchWithAppend();
         test.testBootClassPathMatch();
     }
 
-    /* Error should be detected if:
+    /* Archive contains boot classes only, with Hello class on -Xbootclasspath/a path.
+     *
+     * Error should be detected if:
      * dump time: -Xbootclasspath/a:${testdir}/hello.jar
      * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar
      */
     public void testBootClassPathMismatch() throws Exception {
         String appJar = JarBuilder.getOrCreateHelloJar();

@@ -69,24 +74,13 @@
         TestCommon.run(
                 "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + otherJar, "Hello")
             .assertAbnormalExit(mismatchMessage);
     }
 
-    /* Error should be detected if:
-     * dump time: <no bootclasspath specified>
-     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
-     */
-    public void testBootClassPathMismatch2() throws Exception {
-        String appJar = JarBuilder.getOrCreateHelloJar();
-        String appClasses[] = {"Hello"};
-        TestCommon.dump(appJar, appClasses);
-        TestCommon.run(
-                "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + appJar, "Hello")
-            .assertAbnormalExit(mismatchMessage);
-    }
-
-    /* No error if:
+    /* Archive contains boot classes only, with Hello loaded from -Xbootclasspath/a at dump time.
+     *
+     * No error if:
      * dump time: -Xbootclasspath/a:${testdir}/hello.jar
      * run-time : -Xbootclasspath/a:${testdir}/hello.jar
      */
     public void testBootClassPathMatch() throws Exception {
         String appJar = TestCommon.getTestJar("hello.jar");

@@ -97,10 +91,40 @@
                 "-cp", appJar, "-verbose:class",
                 "-Xbootclasspath/a:" + appJar, "Hello")
             .assertNormalExit("[class,load] Hello source: shared objects file");
     }
 
+    /* Archive contains boot classes only, runtime add -Xbootclasspath/a path.
+     *
+     * No error:
+     * dump time: No -Xbootclasspath/a
+     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
+     */
+    public void testBootClassPathMismatchWithAppend() throws Exception {
+      String appJar = JarBuilder.getOrCreateHelloJar();
+      CDSOptions opts = new CDSOptions().setUseVersion(false);
+      OutputAnalyzer out = CDSTestUtils.createArchive(opts);
+      CDSTestUtils.checkDump(out);
+      opts.addPrefix("-Xbootclasspath/a:" + appJar, "-showversion").addSuffix("Hello");
+      CDSTestUtils.runWithArchiveAndCheck(opts);
+    }
+
+    /* Archive contains app classes, with Hello on -cp path at dump time.
+     *
+     * Error should be detected if:
+     * dump time: <no bootclasspath specified>
+     * run-time : -Xbootclasspath/a:${testdir}/hello.jar
+     */
+    public void testBootClassPathMismatch2() throws Exception {
+        String appJar = JarBuilder.getOrCreateHelloJar();
+        String appClasses[] = {"Hello"};
+        TestCommon.dump(appJar, appClasses);
+        TestCommon.run(
+                "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + appJar, "Hello")
+            .assertAbnormalExit(mismatchMessage);
+    }
+
     private static void copyHelloToNewDir() throws Exception {
         String classDir = System.getProperty("test.classes");
         String dstDir = classDir + File.separator + "newdir";
         try {
             Files.createDirectory(Paths.get(dstDir));
< prev index next >