From f9ee4bc16c6b8694b22546d1e6c97457df25cdd1 Mon Sep 17 00:00:00 2001 From: lujie Date: Thu, 30 Sep 2021 18:20:48 +0800 Subject: [PATCH 1/2] resource leak due Files.list --- .../buck/features/python/MovePythonWhlDataStep.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java b/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java index a966d1bcae5..c0b8bba5374 100644 --- a/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java +++ b/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java @@ -25,6 +25,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Optional; +import java.util.stream.Stream; /** * A {@link Step} that moves the contents of the {package}-{version}.data directory within an @@ -56,11 +57,12 @@ public StepExecutionResult execute(ExecutionContext context) throws IOException // to just list the couple of entries inside of the root of the extracted dir, rather than // parsing out the *.dist-info/METADATA file (we also would need the package name/version // anyways to find the .dist-info dir. - Optional dataDir = - Files.list(resolvedWhlDir) - .filter( - path -> path.getFileName().toString().endsWith(".data") && Files.isDirectory(path)) - .findFirst(); + Optional dataDir = null; + try(Stream list = Files.list(resolvedWhlDir)) { + dataDir = list.filter( + path -> path.getFileName().toString().endsWith(".data") && Files.isDirectory(path)) + .findFirst(); + } if (!dataDir.isPresent()) { return StepExecutionResults.SUCCESS; } From ca16bc4b9d367acc67c9c3e9194feba0436adcb7 Mon Sep 17 00:00:00 2001 From: lujie Date: Sat, 2 Oct 2021 22:05:19 +0800 Subject: [PATCH 2/2] use Google Java Format --- .../facebook/buck/features/python/MovePythonWhlDataStep.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java b/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java index c0b8bba5374..4edc8907d86 100644 --- a/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java +++ b/src/com/facebook/buck/features/python/MovePythonWhlDataStep.java @@ -57,8 +57,8 @@ public StepExecutionResult execute(ExecutionContext context) throws IOException // to just list the couple of entries inside of the root of the extracted dir, rather than // parsing out the *.dist-info/METADATA file (we also would need the package name/version // anyways to find the .dist-info dir. - Optional dataDir = null; - try(Stream list = Files.list(resolvedWhlDir)) { + Optional dataDir = Optional.empty(); + try (Stream list = Files.list(resolvedWhlDir)) { dataDir = list.filter( path -> path.getFileName().toString().endsWith(".data") && Files.isDirectory(path)) .findFirst();