langtools/test/tools/javac/T6351767.java
changeset 27319 030080f03e4f
parent 5520 86e4b9a9da40
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/T6351767.java	Wed Oct 29 12:09:17 2014 +0100
+++ b/langtools/test/tools/javac/T6351767.java	Wed Oct 29 17:25:23 2014 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 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
@@ -38,52 +38,52 @@
     public static void main(String... args) throws Exception {
 
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
-        JavaFileManager jfm = compiler.getStandardFileManager(null, null, null);
+        try (JavaFileManager jfm = compiler.getStandardFileManager(null, null, null)) {
 
-        // test null
-        try {
-            jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
-            error("NPE not thrown");
-        }
-        catch (NullPointerException e) {
-            // expected
-        }
+            // test null
+            try {
+                jfm.list(StandardLocation.SOURCE_PATH, null, EnumSet.of(Kind.SOURCE), false);
+                error("NPE not thrown");
+            }
+            catch (NullPointerException e) {
+                // expected
+            }
 
-        // test null fileKinds
-        try {
-            jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
-            error("NPE not thrown");
-        }
-        catch (NullPointerException e) {
-            // expected
-        }
+            // test null fileKinds
+            try {
+                jfm.list(StandardLocation.SOURCE_PATH, "", null, false);
+                error("NPE not thrown");
+            }
+            catch (NullPointerException e) {
+                // expected
+            }
 
-        // test good package
-        boolean found = false;
-        for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
-                                           "java.lang",
-                                           EnumSet.of(Kind.CLASS),
-                                           false)) {
-            System.err.println("found " + jfo.toUri());
-            if (jfo.isNameCompatible("Object", Kind.CLASS))
-                found = true;
-        }
-        if (!found)
-            error("expected file, java/lang/Object.class, not found");
+            // test good package
+            boolean found = false;
+            for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
+                                               "java.lang",
+                                               EnumSet.of(Kind.CLASS),
+                                               false)) {
+                System.err.println("found " + jfo.toUri());
+                if (jfo.isNameCompatible("Object", Kind.CLASS))
+                    found = true;
+            }
+            if (!found)
+                error("expected file, java/lang/Object.class, not found");
 
-        found = false;
-        // test good package (VM name)
-        for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
-                                           "java/lang",
-                                           EnumSet.of(Kind.CLASS),
-                                           false)) {
-            System.err.println("found " + jfo.toUri());
-            if (jfo.isNameCompatible("Object", Kind.CLASS))
-                found = true;
+            found = false;
+            // test good package (VM name)
+            for (JavaFileObject jfo : jfm.list(StandardLocation.PLATFORM_CLASS_PATH,
+                                               "java/lang",
+                                               EnumSet.of(Kind.CLASS),
+                                               false)) {
+                System.err.println("found " + jfo.toUri());
+                if (jfo.isNameCompatible("Object", Kind.CLASS))
+                    found = true;
+            }
+            if (!found)
+                error("expected file, java/lang/Object.class, not found");
         }
-        if (!found)
-            error("expected file, java/lang/Object.class, not found");
-
     }
 
     static void error(String msg) {