The program can potentially fail to release a system resource.
@@ -500,14 +500,7 @@ public abstract class AbstractCommandLineRunner<A extends Compiler,
@GwtIncompatible("Unnecessary")
public static List<SourceFile> getBuiltinExterns(CompilerOptions.Environment env)
throws IOException {
- InputStream input = AbstractCommandLineRunner.class.getResourceAsStream(
- "/externs.zip");
- if (input == null) {
- // In some environments, the externs.zip is relative to this class.
- input = AbstractCommandLineRunner.class.getResourceAsStream("externs.zip");
- }
- checkNotNull(input);
-
+ try (InputStream input = getExternsInput()) {
ZipInputStream zip = new ZipInputStream(input);
String envPrefix = Ascii.toLowerCase(env.toString()) + "/";
Map<String, SourceFile> mapFromExternsZip = new HashMap<>();
@@ -524,19 +517,29 @@ public abstract class AbstractCommandLineRunner<A extends Compiler,
filename = filename.substring(envPrefix.length()); // remove envPrefix, including '/'
}
- BufferedInputStream entryStream = new BufferedInputStream(
- ByteStreams.limit(zip, entry.getSize()));
- mapFromExternsZip.put(filename,
+ BufferedInputStream entryStream =
+ new BufferedInputStream(ByteStreams.limit(zip, entry.getSize()));
+ mapFromExternsZip.put(
+ filename,
SourceFile.fromInputStream(
// Give the files an odd prefix, so that they do not conflict
// with the user's files.
- "externs.zip//" + filename,
- entryStream,
- UTF_8));
+ "externs.zip//" + filename, entryStream, UTF_8));
}
-
return DefaultExterns.prepareExterns(env, mapFromExternsZip);
}
+ }
+
+ @GwtIncompatible("Unnecessary")
+ private static InputStream getExternsInput() {
+ InputStream input = AbstractCommandLineRunner.class.getResourceAsStream("/externs.zip");
+ if (input == null) {
+ // In some environments, the externs.zip is relative to this class.
+ input = AbstractCommandLineRunner.class.getResourceAsStream("externs.zip");
+ }
+ checkNotNull(input);
+ return input;
+ }
/** Runs the Compiler and calls System.exit() with the exit status of the compiler. */
@GwtIncompatible("Unnecessary")
