Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
d767fd86
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d767fd86
编写于
5月 15, 2009
作者:
R
rupashka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
Reviewed-by: malenkov, peterz
上级
e0aa625d
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
197 addition
and
78 deletion
+197
-78
src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java
...e/classes/javax/swing/plaf/basic/BasicDirectoryModel.java
+29
-34
src/share/classes/sun/awt/shell/ShellFolder.java
src/share/classes/sun/awt/shell/ShellFolder.java
+45
-29
src/windows/classes/sun/awt/shell/Win32ShellFolder2.java
src/windows/classes/sun/awt/shell/Win32ShellFolder2.java
+14
-6
src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
...ndows/classes/sun/awt/shell/Win32ShellFolderManager2.java
+10
-9
test/javax/swing/JFileChooser/6713352/bug6713352.java
test/javax/swing/JFileChooser/6713352/bug6713352.java
+99
-0
未找到文件。
src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java
浏览文件 @
d767fd86
...
...
@@ -230,51 +230,46 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh
}
public
void
run0
()
{
DoChangeContents
doChangeContents
=
ShellFolder
.
getInvoker
().
invoke
(
new
Callable
<
DoChangeContents
>()
{
public
DoChangeContents
call
()
throws
Exception
{
FileSystemView
fileSystem
=
filechooser
.
getFileSystemView
();
File
[]
list
=
fileSystem
.
getFiles
(
currentDirectory
,
filechooser
.
isFileHidingEnabled
());
Vector
<
File
>
acceptsList
=
new
Vector
<
File
>();
if
(
isInterrupted
())
{
return
null
;
return
;
}
final
Vector
<
File
>
newFileCache
=
new
Vector
<
File
>();
Vector
<
File
>
newFiles
=
new
Vector
<
File
>();
// run through the file list, add directories and selectable files to fileCache
// Note that this block must be OUTSIDE of Invoker thread because of
// deadlock possibility with custom synchronized FileSystemView
for
(
File
file
:
list
)
{
if
(
filechooser
.
accept
(
file
))
{
acceptsList
.
addElement
(
file
);
}
}
if
(
isInterrupted
())
{
return
null
;
}
// First sort alphabetically by filename
sort
(
acceptsList
);
boolean
isTraversable
=
filechooser
.
isTraversable
(
file
);
Vector
<
File
>
newDirectories
=
new
Vector
<
File
>(
50
);
Vector
<
File
>
newFiles
=
new
Vector
<
File
>();
// run through list grabbing directories in chunks of ten
for
(
int
i
=
0
;
i
<
acceptsList
.
size
();
i
++)
{
File
f
=
acceptsList
.
elementAt
(
i
);
boolean
isTraversable
=
filechooser
.
isTraversable
(
f
);
if
(
isTraversable
)
{
newDirectories
.
addElement
(
f
);
}
else
if
(!
isTraversable
&&
filechooser
.
isFileSelectionEnabled
())
{
newFiles
.
addElement
(
f
);
newFileCache
.
addElement
(
file
);
}
else
if
(
filechooser
.
isFileSelectionEnabled
())
{
newFiles
.
addElement
(
file
);
}
if
(
isInterrupted
())
{
return
null
;
return
;
}
}
}
Vector
<
File
>
newFileCache
=
new
Vector
<
File
>(
newDirectories
);
// First sort alphabetically by filename
sort
(
newFileCache
);
sort
(
newFiles
);
newFileCache
.
addAll
(
newFiles
);
// To avoid loads of synchronizations with Invoker and improve performance we
// execute the whole block on the COM thread
DoChangeContents
doChangeContents
=
ShellFolder
.
getInvoker
().
invoke
(
new
Callable
<
DoChangeContents
>()
{
public
DoChangeContents
call
()
throws
Exception
{
int
newSize
=
newFileCache
.
size
();
int
oldSize
=
fileCache
.
size
();
...
...
src/share/classes/sun/awt/shell/ShellFolder.java
浏览文件 @
d767fd86
...
...
@@ -274,11 +274,15 @@ public abstract class ShellFolder extends File {
// Override File methods
public
static
void
sort
(
List
<?
extends
File
>
files
)
{
public
static
void
sort
(
final
List
<?
extends
File
>
files
)
{
if
(
files
==
null
||
files
.
size
()
<=
1
)
{
return
;
}
// To avoid loads of synchronizations with Invoker and improve performance we
// synchronize the whole code of the sort method once
getInvoker
().
invoke
(
new
Callable
<
Void
>()
{
public
Void
call
()
throws
Exception
{
// Check that we can use the ShellFolder.sortChildren() method:
// 1. All files have the same non-null parent
// 2. All files is ShellFolders
...
...
@@ -309,10 +313,22 @@ public abstract class ShellFolder extends File {
}
else
{
Collections
.
sort
(
files
,
FILE_COMPARATOR
);
}
return
null
;
}
});
}
public
void
sortChildren
(
List
<?
extends
File
>
files
)
{
public
void
sortChildren
(
final
List
<?
extends
File
>
files
)
{
// To avoid loads of synchronizations with Invoker and improve performance we
// synchronize the whole code of the sort method once
getInvoker
().
invoke
(
new
Callable
<
Void
>()
{
public
Void
call
()
throws
Exception
{
Collections
.
sort
(
files
,
FILE_COMPARATOR
);
return
null
;
}
});
}
public
boolean
isAbsolute
()
{
...
...
src/windows/classes/sun/awt/shell/Win32ShellFolder2.java
浏览文件 @
d767fd86
...
...
@@ -527,7 +527,7 @@ final class Win32ShellFolder2 extends ShellFolder {
/**
* @return Whether this is a file system shell folder
*/
public
synchronized
boolean
isFileSystem
()
{
public
boolean
isFileSystem
()
{
if
(
cachedIsFileSystem
==
null
)
{
cachedIsFileSystem
=
hasAttribute
(
ATTRIB_FILESYSTEM
);
}
...
...
@@ -761,7 +761,7 @@ final class Win32ShellFolder2 extends ShellFolder {
/**
* @return Whether this shell folder is a link
*/
public
synchronized
boolean
isLink
()
{
public
boolean
isLink
()
{
if
(
cachedIsLink
==
null
)
{
cachedIsLink
=
hasAttribute
(
ATTRIB_LINK
);
}
...
...
@@ -1160,8 +1160,16 @@ final class Win32ShellFolder2 extends ShellFolder {
private
static
native
int
compareIDsByColumn
(
long
pParentIShellFolder
,
long
pidl1
,
long
pidl2
,
int
columnIdx
);
public
void
sortChildren
(
List
<?
extends
File
>
files
)
{
public
void
sortChildren
(
final
List
<?
extends
File
>
files
)
{
// To avoid loads of synchronizations with Invoker and improve performance we
// synchronize the whole code of the sort method once
getInvoker
().
invoke
(
new
Callable
<
Void
>()
{
public
Void
call
()
throws
Exception
{
Collections
.
sort
(
files
,
new
ColumnComparator
(
getIShellFolder
(),
0
));
return
null
;
}
});
}
private
static
class
ColumnComparator
implements
Comparator
<
File
>
{
...
...
src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
浏览文件 @
d767fd86
...
...
@@ -478,21 +478,22 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
public
<
T
>
T
invoke
(
Callable
<
T
>
task
)
{
try
{
T
result
;
if
(
Thread
.
currentThread
()
==
comThread
)
{
// if it's already called from the COM
// thread, we don't need to delegate the task
re
sult
=
task
.
call
();
re
turn
task
.
call
();
}
else
{
while
(
true
)
{
Future
<
T
>
future
=
submit
(
task
);
try
{
result
=
future
.
get
();
return
future
.
get
();
}
catch
(
InterruptedException
e
)
{
result
=
null
;
// Repeat the attempt
future
.
cancel
(
true
);
}
}
return
result
;
}
}
catch
(
Exception
e
)
{
Throwable
cause
=
(
e
instanceof
ExecutionException
)
?
e
.
getCause
()
:
e
;
if
(
cause
instanceof
RuntimeException
)
{
...
...
test/javax/swing/JFileChooser/6713352/bug6713352.java
0 → 100644
浏览文件 @
d767fd86
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@bug 6713352
@summary Deadlock in JFileChooser with synchronized custom FileSystemView
@author Pavel Porvatov
@run main bug6713352
*/
import
sun.awt.shell.ShellFolder
;
import
javax.swing.*
;
import
javax.swing.filechooser.FileSystemView
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
public
class
bug6713352
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SwingUtilities
.
invokeAndWait
(
new
Runnable
()
{
public
void
run
()
{
MyFileSystemView
systemView
=
new
MyFileSystemView
();
synchronized
(
systemView
)
{
// Get SystemView lock
new
JFileChooser
(
systemView
);
// Wait a little bit. BasicDirectoryModel will lock Invoker and stop on
// the bug6713352.MyFileSystemView.getFiles() method
try
{
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
try
{
System
.
out
.
println
(
"Try to get Invokers lock"
);
ShellFolder
.
getShellFolder
(
new
File
(
"c:/"
)).
listFiles
(
true
);
}
catch
(
FileNotFoundException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
// To avoid RejectedExecutionException in BasicDirectoryModel wait a second
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
});
}
private
static
class
MyFileSystemView
extends
FileSystemView
{
public
File
createNewFolder
(
File
containingDir
)
throws
IOException
{
return
null
;
}
public
File
[]
getFiles
(
File
dir
,
boolean
useFileHiding
)
{
System
.
out
.
println
(
"getFiles start"
);
File
[]
result
;
synchronized
(
this
)
{
result
=
super
.
getFiles
(
dir
,
useFileHiding
);
}
System
.
out
.
println
(
"getFiles finished"
);
return
result
;
}
public
synchronized
Boolean
isTraversable
(
File
f
)
{
return
super
.
isTraversable
(
f
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录