Skip to content

Commit

Permalink
8331467: FileSystems.getDefault fails with ClassNotFoundException if …
Browse files Browse the repository at this point in the history
…custom default provider is in run-time image

Reviewed-by: alanb, jpai
  • Loading branch information
liyazzi authored and Alan Bateman committed Dec 20, 2024
1 parent 35fafbc commit 54f3475
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,8 +27,9 @@

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;
Expand All @@ -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<>();

Expand Down
4 changes: 1 addition & 3 deletions test/jdk/java/nio/file/spi/SetDefaultProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 4313887 7006126 8142968 8178380 8183320 8210112 8266345 8263940
* @bug 4313887 7006126 8142968 8178380 8183320 8210112 8266345 8263940 8331467
* @modules jdk.jartool jdk.jlink
* @library /test/lib
* @build testfsp/* testapp/*
Expand All @@ -45,7 +45,6 @@

import jdk.test.lib.process.ProcessTools;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -124,7 +123,6 @@ void testFspOnModulePath2() throws Exception {
/**
* Test file system provider linked into run-time image.
*/
@Disabled
@Test
void testFspInRuntimeImage() throws Exception {
String image = "image";
Expand Down

0 comments on commit 54f3475

Please sign in to comment.