mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 06:14:49 +02:00
8331467: FileSystems.getDefault fails with ClassNotFoundException if custom default provider is in run-time image
Reviewed-by: alanb, jpai
This commit is contained in:
parent
35fafbc597
commit
54f34750ed
2 changed files with 21 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2024, 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
|
||||
|
@ -27,8 +27,9 @@ package jdk.internal.jimage;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -47,8 +48,23 @@ public class ImageReaderFactory {
|
|||
private ImageReaderFactory() {}
|
||||
|
||||
private static final String JAVA_HOME = System.getProperty("java.home");
|
||||
private static final Path BOOT_MODULES_JIMAGE =
|
||||
Paths.get(JAVA_HOME, "lib", "modules");
|
||||
private static final Path BOOT_MODULES_JIMAGE;
|
||||
|
||||
static {
|
||||
FileSystem fs;
|
||||
if (ImageReaderFactory.class.getClassLoader() == null) {
|
||||
try {
|
||||
fs = (FileSystem) Class.forName("sun.nio.fs.DefaultFileSystemProvider")
|
||||
.getMethod("theFileSystem")
|
||||
.invoke(null);
|
||||
} catch (Exception e) {
|
||||
throw new ExceptionInInitializerError(e);
|
||||
}
|
||||
} else {
|
||||
fs = FileSystems.getDefault();
|
||||
}
|
||||
BOOT_MODULES_JIMAGE = fs.getPath(JAVA_HOME, "lib", "modules");
|
||||
}
|
||||
|
||||
private static final Map<Path, ImageReader> readers = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue