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 /* 26 * @test 27 * @summary bootclasspath mismatch test. 28 * @requires vm.cds 29 * @library /test/lib 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * jdk.jartool/sun.tools.jar 33 * @compile test-classes/Hello.java 34 * @run main BootClassPathMismatch 35 */ 36 37 import jdk.test.lib.process.OutputAnalyzer; 38 import java.io.File; 39 import java.nio.file.Files; 40 import java.nio.file.FileAlreadyExistsException; 41 import java.nio.file.StandardCopyOption; 42 import java.nio.file.Paths; 43 44 45 public class BootClassPathMismatch { 46 private static final String mismatchMessage = "shared class paths mismatch"; 47 48 public static void main(String[] args) throws Exception { 49 JarBuilder.getOrCreateHelloJar(); 50 copyHelloToNewDir(); 51 52 BootClassPathMismatch test = new BootClassPathMismatch(); 53 test.testBootClassPathMismatch(); 54 test.testBootClassPathMismatch2(); 55 test.testBootClassPathMatch(); 56 } 57 58 /* Error should be detected if: 59 * dump time: -Xbootclasspath/a:${testdir}/hello.jar 60 * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar 61 */ 62 public void testBootClassPathMismatch() throws Exception { 63 String appJar = JarBuilder.getOrCreateHelloJar(); 64 String appClasses[] = {"Hello"}; 65 TestCommon.dump( 66 appJar, appClasses, "-Xbootclasspath/a:" + appJar); 67 String testDir = TestCommon.getTestDir("newdir"); 68 String otherJar = testDir + File.separator + "hello.jar"; 69 TestCommon.run( 70 "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + otherJar, "Hello") 71 .assertAbnormalExit(mismatchMessage); 72 } 73 74 /* Error should be detected if: 75 * dump time: <no bootclasspath specified> 76 * run-time : -Xbootclasspath/a:${testdir}/hello.jar 77 */ 78 public void testBootClassPathMismatch2() throws Exception { 79 String appJar = JarBuilder.getOrCreateHelloJar(); 80 String appClasses[] = {"Hello"}; 81 TestCommon.dump(appJar, appClasses); 82 TestCommon.run( 83 "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + appJar, "Hello") 84 .assertAbnormalExit(mismatchMessage); 85 } 86 87 /* No error if: 88 * dump time: -Xbootclasspath/a:${testdir}/hello.jar 89 * run-time : -Xbootclasspath/a:${testdir}/hello.jar 90 */ 91 public void testBootClassPathMatch() throws Exception { 92 String appJar = TestCommon.getTestJar("hello.jar"); 93 String appClasses[] = {"Hello"}; 94 TestCommon.dump( 95 appJar, appClasses, "-Xbootclasspath/a:" + appJar); 96 TestCommon.run( 97 "-cp", appJar, "-verbose:class", 98 "-Xbootclasspath/a:" + appJar, "Hello") 99 .assertNormalExit("[class,load] Hello source: shared objects file"); 100 } 101 102 private static void copyHelloToNewDir() throws Exception { 103 String classDir = System.getProperty("test.classes"); 104 String dstDir = classDir + File.separator + "newdir"; 105 try { 106 Files.createDirectory(Paths.get(dstDir)); 107 } catch (FileAlreadyExistsException e) { } 108 109 Files.copy(Paths.get(classDir, "hello.jar"), 110 Paths.get(dstDir, "hello.jar"), 111 StandardCopyOption.REPLACE_EXISTING); 112 } 113 } | 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 /* 26 * @test 27 * @summary bootclasspath mismatch test. 28 * @requires vm.cds 29 * @library /test/lib 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * jdk.jartool/sun.tools.jar 33 * @compile test-classes/Hello.java 34 * @run main BootClassPathMismatch 35 */ 36 37 import jdk.test.lib.cds.CDSOptions; 38 import jdk.test.lib.cds.CDSTestUtils; 39 import jdk.test.lib.process.OutputAnalyzer; 40 import java.io.File; 41 import java.nio.file.Files; 42 import java.nio.file.FileAlreadyExistsException; 43 import java.nio.file.StandardCopyOption; 44 import java.nio.file.Paths; 45 46 47 public class BootClassPathMismatch { 48 private static final String mismatchMessage = "shared class paths mismatch"; 49 50 public static void main(String[] args) throws Exception { 51 JarBuilder.getOrCreateHelloJar(); 52 copyHelloToNewDir(); 53 54 BootClassPathMismatch test = new BootClassPathMismatch(); 55 test.testBootClassPathMismatch(); 56 test.testBootClassPathMismatch2(); 57 test.testBootClassPathMismatchWithAppend(); 58 test.testBootClassPathMatch(); 59 } 60 61 /* Archive contains boot classes only, with Hello class on -Xbootclasspath/a path. 62 * 63 * Error should be detected if: 64 * dump time: -Xbootclasspath/a:${testdir}/hello.jar 65 * run-time : -Xbootclasspath/a:${testdir}/newdir/hello.jar 66 */ 67 public void testBootClassPathMismatch() throws Exception { 68 String appJar = JarBuilder.getOrCreateHelloJar(); 69 String appClasses[] = {"Hello"}; 70 TestCommon.dump( 71 appJar, appClasses, "-Xbootclasspath/a:" + appJar); 72 String testDir = TestCommon.getTestDir("newdir"); 73 String otherJar = testDir + File.separator + "hello.jar"; 74 TestCommon.run( 75 "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + otherJar, "Hello") 76 .assertAbnormalExit(mismatchMessage); 77 } 78 79 /* Archive contains boot classes only, with Hello loaded from -Xbootclasspath/a at dump time. 80 * 81 * No error if: 82 * dump time: -Xbootclasspath/a:${testdir}/hello.jar 83 * run-time : -Xbootclasspath/a:${testdir}/hello.jar 84 */ 85 public void testBootClassPathMatch() throws Exception { 86 String appJar = TestCommon.getTestJar("hello.jar"); 87 String appClasses[] = {"Hello"}; 88 TestCommon.dump( 89 appJar, appClasses, "-Xbootclasspath/a:" + appJar); 90 TestCommon.run( 91 "-cp", appJar, "-verbose:class", 92 "-Xbootclasspath/a:" + appJar, "Hello") 93 .assertNormalExit("[class,load] Hello source: shared objects file"); 94 } 95 96 /* Archive contains boot classes only, runtime add -Xbootclasspath/a path. 97 * 98 * No error: 99 * dump time: No -Xbootclasspath/a 100 * run-time : -Xbootclasspath/a:${testdir}/hello.jar 101 */ 102 public void testBootClassPathMismatchWithAppend() throws Exception { 103 String appJar = JarBuilder.getOrCreateHelloJar(); 104 CDSOptions opts = new CDSOptions().setUseVersion(false); 105 OutputAnalyzer out = CDSTestUtils.createArchive(opts); 106 CDSTestUtils.checkDump(out); 107 opts.addPrefix("-Xbootclasspath/a:" + appJar, "-showversion").addSuffix("Hello"); 108 CDSTestUtils.runWithArchiveAndCheck(opts); 109 } 110 111 /* Archive contains app classes, with Hello on -cp path at dump time. 112 * 113 * Error should be detected if: 114 * dump time: <no bootclasspath specified> 115 * run-time : -Xbootclasspath/a:${testdir}/hello.jar 116 */ 117 public void testBootClassPathMismatch2() throws Exception { 118 String appJar = JarBuilder.getOrCreateHelloJar(); 119 String appClasses[] = {"Hello"}; 120 TestCommon.dump(appJar, appClasses); 121 TestCommon.run( 122 "-cp", appJar, "-verbose:class", "-Xbootclasspath/a:" + appJar, "Hello") 123 .assertAbnormalExit(mismatchMessage); 124 } 125 126 private static void copyHelloToNewDir() throws Exception { 127 String classDir = System.getProperty("test.classes"); 128 String dstDir = classDir + File.separator + "newdir"; 129 try { 130 Files.createDirectory(Paths.get(dstDir)); 131 } catch (FileAlreadyExistsException e) { } 132 133 Files.copy(Paths.get(classDir, "hello.jar"), 134 Paths.get(dstDir, "hello.jar"), 135 StandardCopyOption.REPLACE_EXISTING); 136 } 137 } |