<i18n dev> RFR: 8290316: Ensure that all directory streams are closed in java.base

Alan Bateman alanb at openjdk.org
Fri Jul 15 16:38:12 UTC 2022


On Fri, 15 Jul 2022 16:06:21 GMT, Ryan Ernst <duke at openjdk.org> wrote:

> This commit guards uses of Files methods returning path streams in
> java.base to use try-with-resources.

Changing these usages to close the stream is good but needs to keep the formatting/style consistent with the existing code. Also can you make sure the copyright date is updated on the files that need it.

src/java.base/share/classes/java/time/chrono/HijrahChronology.java line 1040:

> 1038:                 if (Files.isDirectory(CONF_PATH)) {
> 1039:                     try (Stream<Path> stream = Files.list(CONF_PATH)) {
> 1040:                             stream.map(p -> p.getFileName().toString())

I can't tell if there is a tab here but it looks like you've changed this to indent by 8 instead of 4 spaces.

src/java.base/share/classes/jdk/internal/module/ModulePatcher.java line 141:

> 139:                                 .map(path -> toPackageName(top, path))
> 140:                                 .filter(Checks::isPackageName)
> 141:                                 .forEach(packages::add);

The formatting seems to a bit messed up here too, I don't know if you means to do that. In the try-block the indentation of stream.filter should be 4 spaces, not 8. Also can you restore the alignment of the expression provided to filter then it will be easier to read.

src/java.base/share/classes/jdk/internal/module/ModulePath.java line 669:

> 667:         try (Stream<Path> stream =
> 668:                 Files.find(dir, Integer.MAX_VALUE, (path, attrs) -> attrs.isRegularFile() && !isHidden(path))) {
> 669:             return stream.map(dir::relativize)

This is inconsistent with existing code. If you change to something like the following then it would make future side-by-side diffs easier to read:

try (Stream<Path> s = Files.find(dir, Integer.MAX_VALUE,
                (path, attrs) -> attrs.isRegularFile() && !isHidden(path))) {
    return s.map(...);
} catch (IOException x) {
    throw new UncheckedIOException(x);
}

-------------

Changes requested by alanb (Reviewer).

PR: https://git.openjdk.org/jdk/pull/9518


More information about the i18n-dev mailing list