mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-16 17:14:41 +02:00
8203354: assert in ClassLoader::update_module_path_entry_list() could have incorrect message
Converting the assert in ClassLoader::update_module_path_entry_list() to a meaningful error message before aborting the CDS dump. Reviewed-by: stuefe, iklam
This commit is contained in:
parent
b83864b498
commit
55b6a9b02b
2 changed files with 52 additions and 3 deletions
|
@ -711,8 +711,11 @@ void ClassLoader::add_to_module_path_entries(const char* path,
|
||||||
void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {
|
void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {
|
||||||
assert(DumpSharedSpaces, "dump time only");
|
assert(DumpSharedSpaces, "dump time only");
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int ret = os::stat(path, &st);
|
if (os::stat(path, &st) != 0) {
|
||||||
assert(ret == 0, "module path must exist");
|
tty->print_cr("os::stat error %d (%s). CDS dump aborted (path was \"%s\").",
|
||||||
|
errno, os::errno_name(errno), path);
|
||||||
|
vm_exit_during_initialization();
|
||||||
|
}
|
||||||
// File or directory found
|
// File or directory found
|
||||||
ClassPathEntry* new_entry = NULL;
|
ClassPathEntry* new_entry = NULL;
|
||||||
new_entry = create_class_path_entry(path, &st, true /* throw_exception */,
|
new_entry = create_class_path_entry(path, &st, true /* throw_exception */,
|
||||||
|
|
|
@ -37,8 +37,10 @@ import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import jdk.test.lib.process.OutputAnalyzer;
|
import jdk.test.lib.process.OutputAnalyzer;
|
||||||
|
import jdk.test.lib.Platform;
|
||||||
import jdk.testlibrary.ProcessTools;
|
import jdk.testlibrary.ProcessTools;
|
||||||
|
|
||||||
public class MainModuleOnly {
|
public class MainModuleOnly {
|
||||||
|
@ -177,10 +179,54 @@ public class MainModuleOnly {
|
||||||
// The dumping process will exit with an error due to non-empty directory
|
// The dumping process will exit with an error due to non-empty directory
|
||||||
// in the --module-path.
|
// in the --module-path.
|
||||||
output = TestCommon.createArchive(destJar.toString(), appClasses,
|
output = TestCommon.createArchive(destJar.toString(), appClasses,
|
||||||
"-Xlog:class+load=trace",
|
|
||||||
"--module-path", MODS_DIR.toString(),
|
"--module-path", MODS_DIR.toString(),
|
||||||
"-m", TEST_MODULE1);
|
"-m", TEST_MODULE1);
|
||||||
output.shouldHaveExitValue(1)
|
output.shouldHaveExitValue(1)
|
||||||
.shouldMatch("Error: non-empty directory.*com.simple");
|
.shouldMatch("Error: non-empty directory.*com.simple");
|
||||||
|
|
||||||
|
// test module path with very long length
|
||||||
|
//
|
||||||
|
// This test can't be run on the windows platform due to an existing
|
||||||
|
// issue in ClassLoader::get_canonical_path() (JDK-8190737).
|
||||||
|
if (Platform.isWindows()) {
|
||||||
|
System.out.println("Long module path test cannot be tested on the Windows platform.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Path longDir = USER_DIR;
|
||||||
|
int pathLen = longDir.toString().length();
|
||||||
|
int PATH_LEN = 2034;
|
||||||
|
int MAX_DIR_LEN = 250;
|
||||||
|
while (pathLen < PATH_LEN) {
|
||||||
|
int remaining = PATH_LEN - pathLen;
|
||||||
|
int subPathLen = remaining > MAX_DIR_LEN ? MAX_DIR_LEN : remaining;
|
||||||
|
char[] chars = new char[subPathLen];
|
||||||
|
Arrays.fill(chars, 'x');
|
||||||
|
String subPath = new String(chars);
|
||||||
|
longDir = Paths.get(longDir.toString(), subPath);
|
||||||
|
pathLen = longDir.toString().length();
|
||||||
|
}
|
||||||
|
File longDirFile = new File(longDir.toString());
|
||||||
|
try {
|
||||||
|
longDirFile.mkdirs();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
Path longDirJar = longDir.resolve(TEST_MODULE1 + ".jar");
|
||||||
|
// IOException results from the Files.copy() call on platform
|
||||||
|
// such as MacOS X. Test can't be proceeded further with the
|
||||||
|
// exception.
|
||||||
|
try {
|
||||||
|
Files.copy(destJar, longDirJar);
|
||||||
|
} catch (java.io.IOException ioe) {
|
||||||
|
System.out.println("Caught IOException from Files.copy(). Cannot continue.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
output = TestCommon.createArchive(destJar.toString(), appClasses,
|
||||||
|
"-Xlog:exceptions=trace",
|
||||||
|
"--module-path", longDirJar.toString(),
|
||||||
|
"-m", TEST_MODULE1);
|
||||||
|
if (output.getExitValue() != 0) {
|
||||||
|
output.shouldMatch("os::stat error.*CDS dump aborted");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue