8189604: possible hang in sun.awt.shell.Win32ShellFolder2$KnownFolderDefinition::<clinit>
authorserb
Thu, 05 Jul 2018 19:05:08 +0300
changeset 50991 a80638fa1a8c
parent 50990 f604d14c8132
child 50992 faf1cd52a5b7
8189604: possible hang in sun.awt.shell.Win32ShellFolder2$KnownFolderDefinition::<clinit> Reviewed-by: prr, kaddepalli
src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java
src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp
test/jdk/javax/swing/reliability/HangDuringStaticInitialization.java
--- a/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Thu Jul 05 13:26:50 2018 +0200
+++ b/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Thu Jul 05 19:05:08 2018 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, 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
@@ -170,7 +170,7 @@
     }
 
     // Known Folder data
-    static class KnownFolderDefinition {
+    static final class KnownFolderDefinition {
         String guid;
         int category;
         String name;
@@ -187,7 +187,10 @@
         String ftidType;
         String path;
         String saveLocation;
-        static final List<KnownFolderDefinition> libraries = getLibraries();
+    }
+
+    static final class KnownLibraries {
+        static final List<KnownFolderDefinition> INSTANCE = getLibraries();
     }
 
     static class FolderDisposer implements sun.java2d.DisposerRecord {
@@ -625,7 +628,7 @@
         // this is a temp fix until java.io starts support Libraries
         if( path != null && path.startsWith("::{") &&
                 path.toLowerCase().endsWith(".library-ms")) {
-            for (KnownFolderDefinition kf : KnownFolderDefinition.libraries) {
+            for (KnownFolderDefinition kf : KnownLibraries.INSTANCE) {
                 if (path.toLowerCase().endsWith(
                         "\\" + kf.relativePath.toLowerCase()) &&
                         path.toUpperCase().startsWith(
--- a/src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp	Thu Jul 05 13:26:50 2018 +0200
+++ b/src/java.desktop/windows/native/libawt/windows/ShellFolder2.cpp	Thu Jul 05 19:05:08 2018 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, 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
@@ -1398,7 +1398,7 @@
     DEFINE_FIELD_ID(field_defenitionFlags, cl, "defenitionFlags", "I");
     DEFINE_FIELD_ID(field_ftidType, cl, "ftidType", "Ljava/lang/String;");
 
-    jobjectArray result;
+    jobjectArray result = NULL;
     KNOWNFOLDERID* pFoldersIds = NULL;
     UINT count = 0;
     if (SUCCEEDED(pkfm->GetFolderIds(&pFoldersIds, &count))) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/reliability/HangDuringStaticInitialization.java	Thu Jul 05 19:05:08 2018 +0300
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+
+/**
+ * @test
+ * @bug 8189604
+ * @run main/othervm -Djava.awt.headless=false HangDuringStaticInitialization
+ * @run main/othervm -Djava.awt.headless=true HangDuringStaticInitialization
+ */
+public final class HangDuringStaticInitialization {
+
+    public static void main(final String[] args) throws Exception {
+        FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
+        test(fs, "/modules/java.desktop");
+        test(fs, "/modules/java.datatransfer");
+    }
+
+    private static void test(FileSystem fs, String s) throws Exception {
+        Files.walkFileTree(fs.getPath(s), new SimpleFileVisitor<>() {
+            @Override
+            public FileVisitResult visitFile(Path file,
+                                             BasicFileAttributes attrs) {
+                file = file.subpath(2, file.getNameCount());
+                String name = file.toString();
+                if (name.endsWith(".class")) {
+                    name = name.substring(0, name.indexOf(".")).replace('/', '.');
+                    try {
+                        Class.forName(name, true, null);
+                    } catch (Throwable e) {
+                        // only the crash / hang will be considered as failure
+                    }
+                }
+                return FileVisitResult.CONTINUE;
+            }
+        });
+    }
+}
\ No newline at end of file