langtools/test/tools/javac/positions/TreeEndPosTest.java
changeset 27319 030080f03e4f
parent 27121 36889255488f
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/positions/TreeEndPosTest.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/positions/TreeEndPosTest.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -137,32 +137,33 @@
         File tempDir = new File(".");
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
         DiagnosticCollector dc = new DiagnosticCollector();
-        JavaFileManager javaFileManager = getJavaFileManager(compiler, dc);
-        List<String> options = new ArrayList<>();
-        options.add("-cp");
-        options.add(tempDir.getPath());
-        options.add("-d");
-        options.add(tempDir.getPath());
-        options.add("-XDshouldStopPolicy=GENERATE");
+        try (JavaFileManager javaFileManager = getJavaFileManager(compiler, dc)) {
+            List<String> options = new ArrayList<>();
+            options.add("-cp");
+            options.add(tempDir.getPath());
+            options.add("-d");
+            options.add(tempDir.getPath());
+            options.add("-XDshouldStopPolicy=GENERATE");
 
-        List<JavaFileObject> sources = new ArrayList<>();
-        sources.add(src);
-        JavaCompiler.CompilationTask task =
-                compiler.getTask(writer, javaFileManager,
-                dc, options, null,
-                sources);
-        task.call();
-        for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) {
-            long actualStart = diagnostic.getStartPosition();
-            long actualEnd = diagnostic.getEndPosition();
-            System.out.println("Source: " + src.source);
-            System.out.println("Diagnostic: " + diagnostic);
-            System.out.print("Start position: Expected: " + src.startPos);
-            System.out.println(", Actual: " + actualStart);
-            System.out.print("End position: Expected: " + src.endPos);
-            System.out.println(", Actual: " + actualEnd);
-            if (src.startPos != actualStart || src.endPos != actualEnd) {
-                throw new RuntimeException("error: trees don't match");
+            List<JavaFileObject> sources = new ArrayList<>();
+            sources.add(src);
+            JavaCompiler.CompilationTask task =
+                    compiler.getTask(writer, javaFileManager,
+                    dc, options, null,
+                    sources);
+            task.call();
+            for (Diagnostic diagnostic : (List<Diagnostic>) dc.getDiagnostics()) {
+                long actualStart = diagnostic.getStartPosition();
+                long actualEnd = diagnostic.getEndPosition();
+                System.out.println("Source: " + src.source);
+                System.out.println("Diagnostic: " + diagnostic);
+                System.out.print("Start position: Expected: " + src.startPos);
+                System.out.println(", Actual: " + actualStart);
+                System.out.print("End position: Expected: " + src.endPos);
+                System.out.println(", Actual: " + actualEnd);
+                if (src.startPos != actualStart || src.endPos != actualEnd) {
+                    throw new RuntimeException("error: trees don't match");
+                }
             }
         }
     }