From 27238601ed7cc7d91a135cb3adf876f8848bb548 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 26 Oct 2009 17:56:52 +0300 Subject: [PATCH] JVM crash fix!!! (no more static fields) --- .../openapi/vfs/impl/win32/Win32Kernel.java | 58 ++++--------------- .../vfs/impl/win32/Win32LocalFileSystem.java | 4 +- 2 files changed, 12 insertions(+), 50 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java index 12a087131f3a..5c9f6ef4d764 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32Kernel.java @@ -34,24 +34,17 @@ import java.util.Map; */ public class Win32Kernel { - private static Kernel32 ourKernel; - private static final int MAX_PATH = 0x00000104; public static final int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; public static final int FILE_ATTRIBUTE_READONLY = 0x0001; - private synchronized static Kernel32 getKernel() { - if (ourKernel == null) { - ourKernel = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class, new HashMap() { + private Kernel32 myKernel = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class, new HashMap() { { put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); }}); - WIN32_FIND_DATA.INSTANCE = new WIN32_FIND_DATA(); - BY_HANDLE_FILE_INFORMATION.INSTANCE = new BY_HANDLE_FILE_INFORMATION(); - } - return ourKernel; - } + + WIN32_FIND_DATA myData = new WIN32_FIND_DATA(); private static class FileInfo { private FileInfo(WIN32_FIND_DATA data) { @@ -59,24 +52,12 @@ public class Win32Kernel { this.ftLastWriteTime = data.ftLastWriteTime.toLong(); } - private FileInfo(BY_HANDLE_FILE_INFORMATION information) { - this.dwFileAttributes = information.dwFileAttributes; - this.ftLastWriteTime = information.ftLastWriteTime.toLong(); - } - int dwFileAttributes; long ftLastWriteTime; } private static W32API.HANDLE INVALID_HANDLE_VALUE = new W32API.HANDLE(Pointer.createConstant(0xFFFFFFFFl)); - public static void release() { - if (ourKernel != null) { - WIN32_FIND_DATA.INSTANCE = null; - BY_HANDLE_FILE_INFORMATION.INSTANCE = null; - } - } - private Map myCache = new HashMap(); public String[] list(String absolutePath) { @@ -84,22 +65,22 @@ public class Win32Kernel { myCache.clear(); ArrayList list = new ArrayList(); - W32API.HANDLE hFind = getKernel().FindFirstFile(absolutePath.replace('/', '\\') + "\\*", WIN32_FIND_DATA.INSTANCE); + W32API.HANDLE hFind = myKernel.FindFirstFile(absolutePath.replace('/', '\\') + "\\*", myData); if (hFind.equals(INVALID_HANDLE_VALUE)) return new String[0]; do { - String name = Native.toString(WIN32_FIND_DATA.INSTANCE.cFileName); + String name = Native.toString(myData.cFileName); if (name.equals(".")) { - myCache.put(absolutePath, new FileInfo(WIN32_FIND_DATA.INSTANCE)); + myCache.put(absolutePath, new FileInfo(myData)); continue; } else if (name.equals("..")) { continue; } - myCache.put(absolutePath + "/" + name, new FileInfo(WIN32_FIND_DATA.INSTANCE)); + myCache.put(absolutePath + "/" + name, new FileInfo(myData)); list.add(name); } - while (getKernel().FindNextFile(hFind, WIN32_FIND_DATA.INSTANCE)); - getKernel().FindClose(hFind); + while (myKernel.FindNextFile(hFind, myData)); + myKernel.FindClose(hFind); return list.toArray(new String[list.size()]); } @@ -131,10 +112,10 @@ public class Win32Kernel { FileInfo data = myCache.get(path); if (data == null) { myCache.clear(); - if (!getKernel().GetFileAttributesEx(path.replace('/', '\\'), 0, BY_HANDLE_FILE_INFORMATION.INSTANCE)) { + if (myKernel.FindFirstFile(path.replace('/', '\\'), myData).equals(INVALID_HANDLE_VALUE)) { throw new FileNotFoundException(path); } - data = new FileInfo(BY_HANDLE_FILE_INFORMATION.INSTANCE); + data = new FileInfo(myData); myCache.put(path, data); } return data; @@ -144,8 +125,6 @@ public class Win32Kernel { W32API.HANDLE FindFirstFile(String lpFileName, WIN32_FIND_DATA lpFindFileData); - boolean GetFileAttributesEx(String lpFileName, int level, BY_HANDLE_FILE_INFORMATION lpFileInformation); - boolean FindNextFile(W32API.HANDLE hFindFile, WIN32_FIND_DATA lpFindFileData); boolean FindClose(W32API.HANDLE hFindFile); @@ -173,8 +152,6 @@ public class Win32Kernel { @SuppressWarnings({"UnusedDeclaration"}) public static class WIN32_FIND_DATA extends Structure { - public static WIN32_FIND_DATA INSTANCE; - public int dwFileAttributes; public FILETIME ftCreationTime; @@ -195,17 +172,4 @@ public class Win32Kernel { public char[] cAlternateFileName = new char[14]; } - - @SuppressWarnings({"UnusedDeclaration"}) - public static class BY_HANDLE_FILE_INFORMATION extends Structure { - - public static BY_HANDLE_FILE_INFORMATION INSTANCE; - - public int dwFileAttributes; - public FILETIME ftCreationTime; - public FILETIME ftLastAccessTime; - public FILETIME ftLastWriteTime; - public int nFileSizeHigh; - public int nFileSizeLow; - } } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java index 6b0fc1c6621f..578aae9a04af 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/win32/Win32LocalFileSystem.java @@ -38,9 +38,7 @@ public class Win32LocalFileSystem extends LocalFileSystemBase { } public static void release() { - if (ourSystem != null) { - Win32Kernel.release(); - } + ourSystem = null; } private final Win32Kernel myKernel = new Win32Kernel();