1.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Sep 20 12:08:48 2011 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Wed Sep 21 21:56:53 2011 -0700 1.3 @@ -488,6 +488,10 @@ 1.4 */ 1.5 public Todo todo; 1.6 1.7 + /** A list of items to be closed when the compilation is complete. 1.8 + */ 1.9 + public List<Closeable> closeables = List.nil(); 1.10 + 1.11 /** Ordered list of compiler phases for each compilation unit. */ 1.12 public enum CompileState { 1.13 PARSE(1), 1.14 @@ -1581,6 +1585,19 @@ 1.15 if (names != null && disposeNames) 1.16 names.dispose(); 1.17 names = null; 1.18 + 1.19 + for (Closeable c: closeables) { 1.20 + try { 1.21 + c.close(); 1.22 + } catch (IOException e) { 1.23 + // When javac uses JDK 7 as a baseline, this code would be 1.24 + // better written to set any/all exceptions from all the 1.25 + // Closeables as suppressed exceptions on the FatalError 1.26 + // that is thrown. 1.27 + JCDiagnostic msg = diagFactory.fragment("fatal.err.cant.close"); 1.28 + throw new FatalError(msg, e); 1.29 + } 1.30 + } 1.31 } 1.32 } 1.33 1.34 @@ -1615,6 +1632,8 @@ 1.35 keepComments = prev.keepComments; 1.36 start_msec = prev.start_msec; 1.37 hasBeenUsed = true; 1.38 + closeables = prev.closeables; 1.39 + prev.closeables = List.nil(); 1.40 } 1.41 1.42 public static void enableLogging() {