--- old/test/tools/launcher/modules/patch/systemmodules/PatchSystemModules.java 2017-04-07 22:37:42.000000000 -0700 +++ new/test/tools/launcher/modules/patch/systemmodules/PatchSystemModules.java 2017-04-07 22:37:42.000000000 -0700 @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,9 +23,8 @@ /* * @test - * @bug 8157068 - * @summary Patch java.base and user module with Hashes attribute tied with - * other module. + * @bug 8157068 8177844 + * @summary Patch java.base and user module with ModuleHashes attribute * @library /lib/testlibrary * @modules jdk.compiler * @build CompilerUtils @@ -59,6 +58,7 @@ private static final Path JARS_DIR = Paths.get("jars"); private static final Path PATCH_DIR = Paths.get("patches"); private static final Path IMAGE = Paths.get("image"); + private static final Path NEW_M1_JAR = JARS_DIR.resolve("new_m1.jar"); private static final String JAVA_BASE = "java.base"; private final String[] modules = new String[] { "m1", "m2" }; @@ -85,8 +85,16 @@ // create an image with m1,m2 createImage(); } + + // create new copy of m1.jar + jar("--create", + "--file=" + NEW_M1_JAR.toString(), + "-C", MODS_DIR.resolve("m1").toString(), "."); } + /* + * Test patching system module and user module on module path + */ @Test public void test() throws Throwable { Path patchedJavaBase = PATCH_DIR.resolve(JAVA_BASE); @@ -107,6 +115,9 @@ "-m", "m1/p1.Main", "2"); } + /* + * Test --patch-module on a custom image + */ @Test public void testImage() throws Throwable { if (Files.notExists(JMODS)) @@ -125,27 +136,49 @@ "-m", "m1/p1.Main", "2"); } + /* + * Test a module linked in a system hashed in ModuleHashes attribute + * cannot be upgraded + */ @Test - public void upgradeTiedModule() throws Throwable { + public void upgradeHashedModule() throws Throwable { if (Files.notExists(JMODS)) return; - Path m1 = MODS_DIR.resolve("m1.jar"); + // Fail to upgrade m1.jar with mismatched hash + runTestWithExitCode(getJava(IMAGE), + "--upgrade-module-path", NEW_M1_JAR.toString(), + "-m", "m1/p1.Main", "ShouldNeverRun"); - // create another m1.jar - jar("--create", - "--file=" + m1.toString(), - "-C", MODS_DIR.resolve("m1").toString(), "."); + // test when SystemModules fast path is not enabled, i.e. exploded image + runTestWithExitCode(getJava(IMAGE), + "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE), + "--upgrade-module-path", NEW_M1_JAR.toString(), + "-m", "m1/p1.Main", "ShouldNeverRun"); + } - // Fail to upgrade m1.jar with mismatched hash + /* + * Test a module linked in a system hashed in ModuleHashes attribute + * cannot be upgraded combining with --patch-module and --upgrade-module-path + */ + @Test + public void patchHashedModule() throws Throwable { + if (Files.notExists(JMODS)) + return; + + // --patch-module does not disable hash check. + // Test that a hashed module cannot be upgraded. runTestWithExitCode(getJava(IMAGE), - "--upgrade-module-path", m1.toString(), - "-m", "m1/p1.Main"); + "--patch-module", "m1=.jar", + "--upgrade-module-path", NEW_M1_JAR.toString(), + "-m", "m1/p1.Main", "ShouldNeverRun"); + // test when SystemModules fast path is not enabled, i.e. exploded image runTestWithExitCode(getJava(IMAGE), "--patch-module", "java.base=" + PATCH_DIR.resolve(JAVA_BASE), - "--upgrade-module-path", m1.toString(), - "-m", "m1/p1.Main", "1"); + "--patch-module", "m1=.jar", + "--upgrade-module-path", NEW_M1_JAR.toString(), + "-m", "m1/p1.Main", "ShouldNeverRun"); } private void runTestWithExitCode(String... options) throws Throwable {