mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8290316: Ensure that all directory streams are closed in java.base
Reviewed-by: chegar
This commit is contained in:
parent
db1e44c2dd
commit
53fc495e3a
5 changed files with 35 additions and 30 deletions
|
@ -86,6 +86,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import sun.util.logging.PlatformLogger;
|
import sun.util.logging.PlatformLogger;
|
||||||
|
|
||||||
|
@ -1035,9 +1036,8 @@ public final class HijrahChronology extends AbstractChronology implements Serial
|
||||||
AccessController.doPrivileged(
|
AccessController.doPrivileged(
|
||||||
(PrivilegedAction<Void>)() -> {
|
(PrivilegedAction<Void>)() -> {
|
||||||
if (Files.isDirectory(CONF_PATH)) {
|
if (Files.isDirectory(CONF_PATH)) {
|
||||||
try {
|
try (Stream<Path> stream = Files.list(CONF_PATH)) {
|
||||||
Files.list(CONF_PATH)
|
stream.map(p -> p.getFileName().toString())
|
||||||
.map(p -> p.getFileName().toString())
|
|
||||||
.filter(fn -> fn.matches("hijrah-config-[^\\.]+\\.properties"))
|
.filter(fn -> fn.matches("hijrah-config-[^\\.]+\\.properties"))
|
||||||
.map(fn -> fn.replaceAll("(hijrah-config-|\\.properties)", ""))
|
.map(fn -> fn.replaceAll("(hijrah-config-|\\.properties)", ""))
|
||||||
.forEach(idtype -> {
|
.forEach(idtype -> {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import jdk.internal.jimage.ImageReader.Node;
|
import jdk.internal.jimage.ImageReader.Node;
|
||||||
|
|
||||||
|
@ -254,10 +255,11 @@ class ExplodedImage extends SystemImage {
|
||||||
String moduleName = module.getFileName().toString();
|
String moduleName = module.getFileName().toString();
|
||||||
// make sure "/modules/<moduleName>" is created
|
// make sure "/modules/<moduleName>" is created
|
||||||
findModulesNode(MODULES + moduleName);
|
findModulesNode(MODULES + moduleName);
|
||||||
Files.walk(module).filter(Files::isDirectory).forEach((p) -> {
|
try (Stream<Path> contentsStream = Files.walk(module)) {
|
||||||
|
contentsStream.filter(Files::isDirectory).forEach((p) -> {
|
||||||
p = module.relativize(p);
|
p = module.relativize(p);
|
||||||
String pkgName = slashesToDots(p.toString());
|
String pkgName = slashesToDots(p.toString());
|
||||||
// skip META-INFO and empty strings
|
// skip META-INF and empty strings
|
||||||
if (!pkgName.isEmpty() && !pkgName.startsWith("META-INF")) {
|
if (!pkgName.isEmpty() && !pkgName.startsWith("META-INF")) {
|
||||||
List<String> moduleNames = packageToModules.get(pkgName);
|
List<String> moduleNames = packageToModules.get(pkgName);
|
||||||
if (moduleNames == null) {
|
if (moduleNames == null) {
|
||||||
|
@ -270,6 +272,7 @@ class ExplodedImage extends SystemImage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// create "/modules" directory
|
// create "/modules" directory
|
||||||
// "nodes" map contains only /modules/<foo> nodes only so far and so add all as children of /modules
|
// "nodes" map contains only /modules/<foo> nodes only so far and so add all as children of /modules
|
||||||
PathNode modulesDir = new PathNode("/modules", new ArrayList<>(nodes.values()));
|
PathNode modulesDir = new PathNode("/modules", new ArrayList<>(nodes.values()));
|
||||||
|
|
|
@ -41,6 +41,7 @@ import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The result of hashing the contents of a number of module artifacts.
|
* The result of hashing the contents of a number of module artifacts.
|
||||||
|
@ -114,9 +115,9 @@ public final class ModuleHashes {
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
byte[] buf = new byte[32*1024];
|
byte[] buf = new byte[32*1024];
|
||||||
reader.list().sorted().forEach(rn -> {
|
try (Stream<String> stream = reader.list()) {
|
||||||
|
stream.sorted().forEach(rn -> {
|
||||||
md.update(rn.getBytes(StandardCharsets.UTF_8));
|
md.update(rn.getBytes(StandardCharsets.UTF_8));
|
||||||
try (InputStream in = reader.open(rn).orElseThrow()) {
|
try (InputStream in = reader.open(rn).orElseThrow()) {
|
||||||
int n;
|
int n;
|
||||||
|
|
|
@ -131,14 +131,15 @@ public final class ModulePatcher {
|
||||||
|
|
||||||
// exploded directory without following sym links
|
// exploded directory without following sym links
|
||||||
Path top = file;
|
Path top = file;
|
||||||
Files.find(top, Integer.MAX_VALUE,
|
try (Stream<Path> stream = Files.find(top, Integer.MAX_VALUE,
|
||||||
((path, attrs) -> attrs.isRegularFile()))
|
((path, attrs) -> attrs.isRegularFile()))) {
|
||||||
.filter(path -> (!isAutomatic
|
stream.filter(path -> (!isAutomatic
|
||||||
|| path.toString().endsWith(".class"))
|
|| path.toString().endsWith(".class"))
|
||||||
&& !isHidden(path))
|
&& !isHidden(path))
|
||||||
.map(path -> toPackageName(top, path))
|
.map(path -> toPackageName(top, path))
|
||||||
.filter(Checks::isPackageName)
|
.filter(Checks::isPackageName)
|
||||||
.forEach(packages::add);
|
.forEach(packages::add);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ import java.util.jar.Manifest;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import java.util.zip.ZipException;
|
import java.util.zip.ZipException;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
@ -663,10 +664,9 @@ public class ModulePath implements ModuleFinder {
|
||||||
|
|
||||||
private Set<String> explodedPackages(Path dir) {
|
private Set<String> explodedPackages(Path dir) {
|
||||||
String separator = dir.getFileSystem().getSeparator();
|
String separator = dir.getFileSystem().getSeparator();
|
||||||
try {
|
try (Stream<Path> stream = Files.find(dir, Integer.MAX_VALUE,
|
||||||
return Files.find(dir, Integer.MAX_VALUE,
|
(path, attrs) -> attrs.isRegularFile() && !isHidden(path))) {
|
||||||
((path, attrs) -> attrs.isRegularFile() && !isHidden(path)))
|
return stream.map(dir::relativize)
|
||||||
.map(path -> dir.relativize(path))
|
|
||||||
.map(path -> toPackageName(path, separator))
|
.map(path -> toPackageName(path, separator))
|
||||||
.flatMap(Optional::stream)
|
.flatMap(Optional::stream)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue