changeset 3341:a399f56c42aa

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
author jlahoda
date Wed, 13 Apr 2016 19:44:19 +0200
parents 65837a9d9c4a
children 9326e37434ee
files test/tools/javac/unit/T6198196.java
diffstat 1 files changed, 23 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/javac/unit/T6198196.java	Wed Apr 13 09:50:48 2016 +0200
+++ b/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);
     }
 }