langtools/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java
changeset 27319 030080f03e4f
parent 20599 5201f7144a3c
child 34752 9c262a013456
--- a/langtools/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/annotations/neg/8022765/VerifyAnnotationsAttributed.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
@@ -41,38 +41,39 @@
         File testSrc = new File(System.getProperty("test.src"));
         File testFile = new File(testSrc, args[0]);
         if (!testFile.canRead()) throw new IllegalStateException("Cannot read the test source");
-        JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
-        JavacTask task = JavacTool.create().getTask(null,
-                                                    fm,
-                                                    null,
-                                                    Collections.<String>emptyList(),
-                                                    null,
-                                                    fm.getJavaFileObjects(testFile));
-        final Trees trees = Trees.instance(task);
-        final CompilationUnitTree cut = task.parse().iterator().next();
-        task.analyze();
+        try (JavacFileManager fm = JavacTool.create().getStandardFileManager(null, null, null)) {
+            JavacTask task = JavacTool.create().getTask(null,
+                                                        fm,
+                                                        null,
+                                                        Collections.<String>emptyList(),
+                                                        null,
+                                                        fm.getJavaFileObjects(testFile));
+            final Trees trees = Trees.instance(task);
+            final CompilationUnitTree cut = task.parse().iterator().next();
+            task.analyze();
 
-        //ensure all the annotation attributes are annotated meaningfully
-        //all the attributes in the test file should contain either an identifier
-        //or a select, so only checking those for a reasonable Element/Symbol.
-        new TreePathScanner<Void, Void>() {
-            @Override
-            public Void visitIdentifier(IdentifierTree node, Void p) {
-                verifyAttributedMeaningfully();
-                return super.visitIdentifier(node, p);
-            }
-            @Override
-            public Void visitMemberSelect(MemberSelectTree node, Void p) {
-                verifyAttributedMeaningfully();
-                return super.visitMemberSelect(node, p);
-            }
-            private void verifyAttributedMeaningfully() {
-                Element el = trees.getElement(getCurrentPath());
+            //ensure all the annotation attributes are annotated meaningfully
+            //all the attributes in the test file should contain either an identifier
+            //or a select, so only checking those for a reasonable Element/Symbol.
+            new TreePathScanner<Void, Void>() {
+                @Override
+                public Void visitIdentifier(IdentifierTree node, Void p) {
+                    verifyAttributedMeaningfully();
+                    return super.visitIdentifier(node, p);
+                }
+                @Override
+                public Void visitMemberSelect(MemberSelectTree node, Void p) {
+                    verifyAttributedMeaningfully();
+                    return super.visitMemberSelect(node, p);
+                }
+                private void verifyAttributedMeaningfully() {
+                    Element el = trees.getElement(getCurrentPath());
 
-                if (el == null || el.getKind() == ElementKind.OTHER) {
-                    throw new IllegalStateException("Not attributed properly: " + getCurrentPath().getParentPath().getLeaf());
+                    if (el == null || el.getKind() == ElementKind.OTHER) {
+                        throw new IllegalStateException("Not attributed properly: " + getCurrentPath().getParentPath().getLeaf());
+                    }
                 }
-            }
-        }.scan(cut, null);
+            }.scan(cut, null);
+        }
     }
 }