8154149: tools/javac/unit/T6198196.java broken on Windows after JDK-8150641
authorjlahoda
Wed, 13 Apr 2016 19:44:19 +0200
changeset 37391 f2750c003cfb
parent 37390 bf1552d6bc16
child 37392 b0c4db80286f
8154149: tools/javac/unit/T6198196.java broken on Windows after JDK-8150641 Summary: Avoiding interference among sub-tests due to CacheFSInfo by using a new file manager for each sub-test Reviewed-by: jjg
langtools/test/tools/javac/unit/T6198196.java
--- a/langtools/test/tools/javac/unit/T6198196.java	Wed Apr 13 09:50:48 2016 +0200
+++ b/langtools/test/tools/javac/unit/T6198196.java	Wed Apr 13 19:44:19 2016 +0200
@@ -36,34 +36,31 @@
 
 public class T6198196 {
     static String pkginf = "package-info";
-    static StandardJavaFileManager fm;
-    static void test(String pathname, String filename, boolean result) {
-        JavaFileObject fo;
-        fo = fm.getJavaFileObjectsFromStrings(Arrays.asList(pathname)).iterator().next();
-        if (result != fo.isNameCompatible(filename, JavaFileObject.Kind.SOURCE))
-            throw new AssertionError("endsWith(" + pathname + ", "
-                                     + filename + ") != " + result);
-        System.out.format("OK: endsWith(%s, %s) = %s%n", pathname, filename, result);
+    static void test(String pathname, String filename, boolean result) throws IOException {
+        try (StandardJavaFileManager fm =
+                ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null)) {
+            JavaFileObject fo =
+                    fm.getJavaFileObjectsFromStrings(Arrays.asList(pathname)).iterator().next();
+            if (result != fo.isNameCompatible(filename, JavaFileObject.Kind.SOURCE))
+                throw new AssertionError("endsWith(" + pathname + ", "
+                                         + filename + ") != " + result);
+            System.out.format("OK: endsWith(%s, %s) = %s%n", pathname, filename, result);
+        }
     }
     public static void main(String[] args) throws IOException {
-        fm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null);
-        try {
-            boolean windows = System.getProperty("os.name").startsWith("Windows");
-            test("/x/y/z/package-info.java", pkginf, true);
-            if (windows) {
-                test("\\x\\y\\z\\package-info.java", pkginf, true);
-                test("..\\x\\y\\z\\package-info.java", pkginf, true);
-            } else {
-                test("\\x\\y\\z\\package-info.java", pkginf, false);
-                test("..\\x\\y\\z\\package-info.java", pkginf, false);
-            }
-            test("Package-info.java", pkginf, false);
-            test("../x/y/z/package-info.java", pkginf, true);
-            test("/x/y/z/package-info.java", pkginf, true);
-            test("x/y/z/package-info.java", pkginf, true);
-            test("package-info.java", pkginf, true);
-        } finally {
-            fm.close();
+        boolean windows = System.getProperty("os.name").startsWith("Windows");
+        test("/x/y/z/package-info.java", pkginf, true);
+        if (windows) {
+            test("\\x\\y\\z\\package-info.java", pkginf, true);
+            test("..\\x\\y\\z\\package-info.java", pkginf, true);
+        } else {
+            test("\\x\\y\\z\\package-info.java", pkginf, false);
+            test("..\\x\\y\\z\\package-info.java", pkginf, false);
         }
+        test("Package-info.java", pkginf, false);
+        test("../x/y/z/package-info.java", pkginf, true);
+        test("/x/y/z/package-info.java", pkginf, true);
+        test("x/y/z/package-info.java", pkginf, true);
+        test("package-info.java", pkginf, true);
     }
 }