langtools/test/tools/javac/6341866/T6341866.java
changeset 27319 030080f03e4f
parent 22444 c79ee1e6742f
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/6341866/T6341866.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/6341866/T6341866.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -113,58 +113,59 @@
 
         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
         MyDiagListener dl = new MyDiagListener();
-        StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null);
+        try (StandardJavaFileManager fm = javac.getStandardFileManager(dl, null, null)) {
 
-        // Note: class A references class B, so compile A if we want implicit compilation
-        File file =  (implicitType != ImplicitType.NONE) ? a_java : b_java;
-        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
-
-        //System.err.println("compile: " + opts + " " + files);
+            // Note: class A references class B, so compile A if we want implicit compilation
+            File file =  (implicitType != ImplicitType.NONE) ? a_java : b_java;
+            Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
 
-        boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
-        if (!ok) {
-            error("compilation failed");
-            return false;
-        }
+            //System.err.println("compile: " + opts + " " + files);
 
-        // check implicit compilation results if necessary
-        if (implicitType != ImplicitType.NONE) {
-            boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
-            if (b_class.exists() != expectClass) {
-                if (b_class.exists())
-                    error("B implicitly compiled unexpectedly");
-                else
-                    error("B not impliictly compiled");
+            boolean ok = javac.getTask(null, fm, dl, opts, null, files).call();
+            if (!ok) {
+                error("compilation failed");
                 return false;
             }
-        }
+
+            // check implicit compilation results if necessary
+            if (implicitType != ImplicitType.NONE) {
+                boolean expectClass = (implicitType != ImplicitType.OPT_NONE);
+                if (b_class.exists() != expectClass) {
+                    if (b_class.exists())
+                        error("B implicitly compiled unexpectedly");
+                    else
+                        error("B not impliictly compiled");
+                    return false;
+                }
+            }
 
-        // check message key results
-        String expectKey = null;
-        if (implicitType == ImplicitType.OPT_UNSET) {
-            switch (annoType) {
-            case SERVICE:
-                expectKey = "compiler.warn.proc.use.proc.or.implicit";
-                break;
-            case SPECIFY:
-                expectKey = "compiler.warn.proc.use.implicit";
-                break;
+            // check message key results
+            String expectKey = null;
+            if (implicitType == ImplicitType.OPT_UNSET) {
+                switch (annoType) {
+                case SERVICE:
+                    expectKey = "compiler.warn.proc.use.proc.or.implicit";
+                    break;
+                case SPECIFY:
+                    expectKey = "compiler.warn.proc.use.implicit";
+                    break;
+                }
             }
+
+            if (expectKey == null) {
+                if (dl.diagCodes.size() != 0) {
+                    error("no diagnostics expected");
+                    return false;
+                }
+            } else {
+                if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
+                    error("unexpected diagnostics generated");
+                    return false;
+                }
+            }
+
+            return true;
         }
-
-        if (expectKey == null) {
-            if (dl.diagCodes.size() != 0) {
-                error("no diagnostics expected");
-                return false;
-            }
-        } else {
-            if (!(dl.diagCodes.size() == 1 && dl.diagCodes.get(0).equals(expectKey))) {
-                error("unexpected diagnostics generated");
-                return false;
-            }
-        }
-
-        return true;
     }
 
     static void createProcessorServices(String name) throws IOException {