Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
83dfb29e
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
83dfb29e
编写于
10月 31, 2014
作者:
A
alexsch
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8062561: Test bug8055304 fails if file system default directory has read access
Reviewed-by: serb
上级
0d6d2bb1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
233 addition
and
14 deletion
+233
-14
src/share/classes/sun/swing/FilePane.java
src/share/classes/sun/swing/FilePane.java
+16
-12
src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
...ndows/classes/sun/awt/shell/Win32ShellFolderManager2.java
+2
-2
test/javax/swing/JFileChooser/8062561/bug8062561.java
test/javax/swing/JFileChooser/8062561/bug8062561.java
+210
-0
test/javax/swing/JFileChooser/8062561/security.policy
test/javax/swing/JFileChooser/8062561/security.policy
+4
-0
test/javax/swing/JFileChooser/8062561/security2.policy
test/javax/swing/JFileChooser/8062561/security2.policy
+1
-0
未找到文件。
src/share/classes/sun/swing/FilePane.java
浏览文件 @
83dfb29e
...
...
@@ -1979,20 +1979,24 @@ public class FilePane extends JPanel implements PropertyChangeListener {
return
false
;
}
if
(
f
instanceof
ShellFolder
)
{
return
f
.
canWrite
();
}
else
{
if
(
usesShellFolder
(
getFileChooser
()))
{
try
{
return
ShellFolder
.
getShellFolder
(
f
).
canWrite
();
}
catch
(
FileNotFoundException
ex
)
{
// File doesn't exist
return
false
;
}
}
else
{
// Ordinary file
try
{
if
(
f
instanceof
ShellFolder
)
{
return
f
.
canWrite
();
}
else
{
if
(
usesShellFolder
(
getFileChooser
()))
{
try
{
return
ShellFolder
.
getShellFolder
(
f
).
canWrite
();
}
catch
(
FileNotFoundException
ex
)
{
// File doesn't exist
return
false
;
}
}
else
{
// Ordinary file
return
f
.
canWrite
();
}
}
}
catch
(
SecurityException
e
)
{
return
false
;
}
}
...
...
src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
浏览文件 @
83dfb29e
...
...
@@ -278,7 +278,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
folders
.
add
(
desktop
);
// Add all second level folders
File
[]
secondLevelFolders
=
desktop
.
listFiles
(
);
File
[]
secondLevelFolders
=
checkFiles
(
desktop
.
listFiles
()
);
Arrays
.
sort
(
secondLevelFolders
);
for
(
File
secondLevelFolder
:
secondLevelFolders
)
{
Win32ShellFolder2
folder
=
(
Win32ShellFolder2
)
secondLevelFolder
;
...
...
@@ -286,7 +286,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
folders
.
add
(
folder
);
// Add third level for "My Computer"
if
(
folder
.
equals
(
drives
))
{
File
[]
thirdLevelFolders
=
folder
.
listFiles
(
);
File
[]
thirdLevelFolders
=
checkFiles
(
folder
.
listFiles
()
);
if
(
thirdLevelFolders
!=
null
&&
thirdLevelFolders
.
length
>
0
)
{
List
<
File
>
thirdLevelFoldersList
=
Arrays
.
asList
(
thirdLevelFolders
);
...
...
test/javax/swing/JFileChooser/8062561/bug8062561.java
0 → 100644
浏览文件 @
83dfb29e
/*
* Copyright (c) 2014, 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.awt.Robot
;
import
java.awt.event.KeyEvent
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.PrintWriter
;
import
java.util.concurrent.TimeUnit
;
import
javax.swing.JFileChooser
;
import
javax.swing.SwingUtilities
;
import
javax.swing.filechooser.FileSystemView
;
import
sun.awt.OSInfo
;
/**
* @test
* @bug 8062561
* @summary File system view returns null default directory
* @run main/othervm bug8062561 GENERATE_POLICY
* @run main/othervm/policy=security.policy bug8062561 CHECK_DEFAULT_DIR run
*/
public
class
bug8062561
{
private
static
final
String
POLICY_FILE
=
"security2.policy"
;
private
static
volatile
boolean
fileChooserIsShown
=
false
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
test
=
args
[
0
];
switch
(
test
)
{
case
"GENERATE_POLICY"
:
generatePolicyFile
();
break
;
case
"CHECK_DEFAULT_DIR"
:
checkDefaultDirectory
();
break
;
case
"CHECK_FILE_CHOOSER"
:
checkFileChooser
();
break
;
default
:
throw
new
RuntimeException
(
"Wrong argument!"
);
}
}
private
static
void
checkDefaultDirectory
()
{
if
(
System
.
getSecurityManager
()
==
null
)
{
throw
new
RuntimeException
(
"Security manager is not set!"
);
}
File
defaultDirectory
=
FileSystemView
.
getFileSystemView
().
getDefaultDirectory
();
if
(
defaultDirectory
!=
null
)
{
throw
new
RuntimeException
(
"File system default directory is null!"
);
}
}
private
static
volatile
JFileChooser
fileChooser
;
private
static
void
checkFileChooser
()
throws
Exception
{
if
(
System
.
getSecurityManager
()
==
null
)
{
throw
new
RuntimeException
(
"Security manager is not set!"
);
}
Robot
robot
=
new
Robot
();
robot
.
setAutoDelay
(
50
);
SwingUtilities
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
fileChooser
=
new
JFileChooser
();
fileChooser
.
showOpenDialog
(
null
);
fileChooserIsShown
=
true
;
System
.
out
.
println
(
"Start file chooser: "
+
fileChooserIsShown
);
}
});
long
time
=
System
.
currentTimeMillis
();
while
(
fileChooser
==
null
)
{
if
(
System
.
currentTimeMillis
()
-
time
>=
10000
)
{
throw
new
RuntimeException
(
"FileChoser is not shown!"
);
}
Thread
.
sleep
(
500
);
}
Thread
.
sleep
(
500
);
robot
.
keyPress
(
KeyEvent
.
VK_ESCAPE
);
robot
.
keyRelease
(
KeyEvent
.
VK_ESCAPE
);
System
.
exit
(
0
);
}
private
static
void
generatePolicyFile
()
throws
Exception
{
if
(
System
.
getSecurityManager
()
!=
null
)
{
throw
new
RuntimeException
(
"Security manager should be null!"
);
}
if
(!
OSInfo
.
getOSType
().
equals
(
OSInfo
.
OSType
.
WINDOWS
))
{
return
;
}
File
defaultDirectory
=
FileSystemView
.
getFileSystemView
().
getDefaultDirectory
();
if
(
defaultDirectory
==
null
)
{
throw
new
RuntimeException
(
"Default directory is null!"
);
}
File
policyFile
=
new
File
(
POLICY_FILE
);
if
(!
policyFile
.
exists
())
{
policyFile
.
createNewFile
();
}
try
(
PrintWriter
writer
=
new
PrintWriter
(
policyFile
,
"UTF-8"
))
{
writer
.
println
(
"grant {"
);
String
documents
=
defaultDirectory
.
getCanonicalPath
();
documents
=
documents
.
replace
(
'\\'
,
'/'
);
// Documents permission
writer
.
print
(
" permission java.io.FilePermission"
);
writer
.
print
(
" \""
+
documents
+
"\","
);
writer
.
println
(
" \"read\";"
);
// Desktop permission
writer
.
print
(
" permission java.io.FilePermission"
);
writer
.
print
(
" \""
+
documents
.
replace
(
"Documents"
,
"Desktop"
)
+
"\","
);
writer
.
println
(
" \"read\";"
);
// robot permission // "java.awt.AWTPermission" "createRobot"
writer
.
print
(
" permission java.awt.AWTPermission"
);
writer
.
println
(
" \"createRobot\";"
);
writer
.
println
(
"};"
);
}
performTest
();
}
private
static
void
performTest
()
throws
Exception
{
String
javaPath
=
System
.
getProperty
(
"java.home"
,
""
);
String
command
=
javaPath
+
File
.
separator
+
"bin"
+
File
.
separator
+
"java"
+
" -Djava.security.manager -Djava.security.policy="
+
POLICY_FILE
+
" bug8062561 CHECK_FILE_CHOOSER"
;
System
.
out
.
println
(
command
);
boolean
processExit
=
false
;
Process
process
=
Runtime
.
getRuntime
().
exec
(
command
);
try
{
processExit
=
process
.
waitFor
(
20
,
TimeUnit
.
SECONDS
);
}
catch
(
IllegalThreadStateException
e
)
{
throw
new
RuntimeException
(
e
);
}
System
.
out
.
println
(
"[RESULT] : "
+
"The sub process has cleanly exited : PASS"
);
InputStream
errorStream
=
process
.
getErrorStream
();
System
.
out
.
println
(
"========= Child process stderr ========"
);
boolean
exception
=
dumpStream
(
errorStream
);
if
(
exception
)
{
throw
new
RuntimeException
(
"[RESULT] :"
+
" Exception in child process : FAIL"
);
}
System
.
out
.
println
(
"======================================="
);
InputStream
processInputStream
=
process
.
getInputStream
();
System
.
out
.
println
(
"========= Child process output ========"
);
dumpStream
(
processInputStream
);
System
.
out
.
println
(
"======================================="
);
if
(!
processExit
)
{
process
.
destroy
();
throw
new
RuntimeException
(
"[RESULT] : "
+
"The sub process has not exited : FAIL"
);
}
}
public
static
boolean
dumpStream
(
InputStream
in
)
throws
IOException
{
String
tempString
;
int
count
=
in
.
available
();
boolean
exception
=
false
;
while
(
count
>
0
)
{
byte
[]
b
=
new
byte
[
count
];
in
.
read
(
b
);
tempString
=
new
String
(
b
);
if
(!
exception
)
{
exception
=
tempString
.
indexOf
(
"Exception"
)
!=
-
1
;
}
System
.
out
.
println
(
tempString
);
count
=
in
.
available
();
}
return
exception
;
}
}
test/javax/swing/JFileChooser/8062561/security.policy
0 → 100644
浏览文件 @
83dfb29e
grant {
permission java.util.PropertyPermission "user.home", "read";
};
test/javax/swing/JFileChooser/8062561/security2.policy
0 → 100644
浏览文件 @
83dfb29e
// Autogenerated file
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录