diff options
Diffstat (limited to 'src/java_tools/singlejar/java/com/google/devtools/build/singlejar/OptionFileExpander.java')
-rw-r--r-- | src/java_tools/singlejar/java/com/google/devtools/build/singlejar/OptionFileExpander.java | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/OptionFileExpander.java b/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/OptionFileExpander.java index 66d4a72579..aa396b5973 100644 --- a/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/OptionFileExpander.java +++ b/src/java_tools/singlejar/java/com/google/devtools/build/singlejar/OptionFileExpander.java @@ -18,7 +18,6 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1; import com.google.devtools.build.lib.shell.ShellUtils; import com.google.devtools.build.lib.shell.ShellUtils.TokenizationException; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -26,7 +25,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.util.ArrayList; import java.util.List; - import javax.annotation.concurrent.Immutable; /** @@ -82,11 +80,11 @@ final class OptionFileExpander { */ private void expandArgument(String arg, List<String> expanded) throws IOException { if (arg.startsWith("@")) { - InputStream in = fileSystem.getInputStream(arg.substring(1)); - try { + try (InputStreamReader reader = + new InputStreamReader(fileSystem.getInputStream(arg.substring(1)), ISO_8859_1)) { // TODO(bazel-team): This code doesn't handle escaped newlines correctly. // ShellUtils doesn't support them either. - for (String line : readAllLines(new InputStreamReader(in, ISO_8859_1))) { + for (String line : readAllLines(reader)) { List<String> parsedTokens = new ArrayList<>(); try { ShellUtils.tokenize(parsedTokens, line); @@ -97,18 +95,6 @@ final class OptionFileExpander { expandArgument(token, expanded); } } - InputStream inToClose = in; - in = null; - inToClose.close(); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - // Ignore the exception. It can only occur if an exception already - // happened and in that case, we want to preserve the original one. - } - } } } else { expanded.add(arg); |