--- old/test/hotspot/jtreg/runtime/cds/appcds/ClassPathAttr.java 2019-08-23 16:50:25.458714217 -0700 +++ new/test/hotspot/jtreg/runtime/cds/appcds/ClassPathAttr.java 2019-08-23 16:50:25.218705652 -0700 @@ -42,6 +42,11 @@ public class ClassPathAttr { public static void main(String[] args) throws Exception { + testNormalOps(); + testNonExistentJars(); + } + + static void testNormalOps() throws Exception { buildCpAttr("cpattr1", "cpattr1.mf", "CpAttr1", "CpAttr1"); buildCpAttr("cpattr1_long", "cpattr1_long.mf", "CpAttr1", "CpAttr1"); buildCpAttr("cpattr2", "cpattr2.mf", "CpAttr2", "CpAttr2"); @@ -93,6 +98,39 @@ } } + static void testNonExistentJars() throws Exception { + buildCpAttr("cpattr6", "cpattr6.mf", "CpAttr6", "CpAttr6"); + + String cp = TestCommon.getTestJar("cpattr6.jar"); + String nonExistPath = System.getProperty("test.classes") + File.separator + "cpattrX.jar"; + (new File(nonExistPath)).delete(); + + TestCommon.testDump(cp, TestCommon.list("CpAttr6"), + "-Xlog:class+path"); + + TestCommon.run( + "-Xlog:class+path", + "-cp", cp, + "CpAttr6") + .assertNormalExit(output -> { + output.shouldMatch("should be non-existent: .*cpattrX.jar"); + }); + + // Now make nonExistPath exist. CDS will fail to load. + Files.copy(Paths.get(cp), Paths.get(nonExistPath), + StandardCopyOption.REPLACE_EXISTING); + + TestCommon.run( + "-Xlog:class+path", + "-cp", cp, + "CpAttr6") + .assertAbnormalExit(output -> { + output.shouldMatch("should be non-existent: .*cpattrX.jar"); + output.shouldMatch("file must not exist: *cpattrX.jar"); + + }); + } + private static void buildCpAttr(String jarName, String manifest, String enclosingClassName, String ...testClassNames) throws Exception { String jarClassesDir = System.getProperty("test.classes") + File.separator + jarName + "_classes"; try { Files.createDirectory(Paths.get(jarClassesDir)); } catch (FileAlreadyExistsException e) { }