Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e0bb1cc8
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看板
提交
e0bb1cc8
编写于
6月 21, 2010
作者:
R
rupashka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6938813: Swing mutable statics
Reviewed-by: peterz, alexp
上级
f1409fc8
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
175 addition
and
20 deletion
+175
-20
src/share/classes/javax/swing/text/html/HTMLEditorKit.java
src/share/classes/javax/swing/text/html/HTMLEditorKit.java
+13
-3
src/share/classes/javax/swing/text/html/parser/DTD.java
src/share/classes/javax/swing/text/html/parser/DTD.java
+24
-7
src/share/classes/javax/swing/text/html/parser/ParserDelegator.java
...classes/javax/swing/text/html/parser/ParserDelegator.java
+13
-10
test/javax/swing/Security/6938813/bug6938813.java
test/javax/swing/Security/6938813/bug6938813.java
+125
-0
未找到文件。
src/share/classes/javax/swing/text/html/HTMLEditorKit.java
浏览文件 @
e0bb1cc8
/*
* Copyright (c) 1997, 20
08
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 20
10
, 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
...
...
@@ -24,6 +24,8 @@
*/
package
javax.swing.text.html
;
import
sun.awt.AppContext
;
import
java.lang.reflect.Method
;
import
java.awt.*
;
import
java.awt.event.*
;
...
...
@@ -369,7 +371,11 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* if desired.
*/
public
void
setStyleSheet
(
StyleSheet
s
)
{
defaultStyles
=
s
;
if
(
s
==
null
)
{
AppContext
.
getAppContext
().
remove
(
DEFAULT_STYLES_KEY
);
}
else
{
AppContext
.
getAppContext
().
put
(
DEFAULT_STYLES_KEY
,
s
);
}
}
/**
...
...
@@ -379,8 +385,12 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
* instances.
*/
public
StyleSheet
getStyleSheet
()
{
AppContext
appContext
=
AppContext
.
getAppContext
();
StyleSheet
defaultStyles
=
(
StyleSheet
)
appContext
.
get
(
DEFAULT_STYLES_KEY
);
if
(
defaultStyles
==
null
)
{
defaultStyles
=
new
StyleSheet
();
appContext
.
put
(
DEFAULT_STYLES_KEY
,
defaultStyles
);
try
{
InputStream
is
=
HTMLEditorKit
.
getResourceAsStream
(
DEFAULT_CSS
);
Reader
r
=
new
BufferedReader
(
...
...
@@ -620,7 +630,7 @@ public class HTMLEditorKit extends StyledEditorKit implements Accessible {
private
static
final
ViewFactory
defaultFactory
=
new
HTMLFactory
();
MutableAttributeSet
input
;
private
static
StyleSheet
defaultStyles
=
null
;
private
static
final
Object
DEFAULT_STYLES_KEY
=
new
Object
()
;
private
LinkController
linkHandler
=
new
LinkController
();
private
static
Parser
defaultParser
=
null
;
private
Cursor
defaultCursor
=
DefaultCursor
;
...
...
src/share/classes/javax/swing/text/html/parser/DTD.java
浏览文件 @
e0bb1cc8
/*
* Copyright (c) 1998, 20
08
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 20
10
, 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
...
...
@@ -25,6 +25,8 @@
package
javax.swing.text.html.parser
;
import
sun.awt.AppContext
;
import
java.io.PrintStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
@@ -314,13 +316,14 @@ class DTD implements DTDConstants {
}
/**
* The hashtable
of DTDs
.
* The hashtable
key of DTDs in AppContext
.
*/
static
Hashtable
<
String
,
DTD
>
dtdHash
=
new
Hashtable
<
String
,
DTD
>
();
private
static
final
Object
DTD_HASH_KEY
=
new
Object
();
public
static
void
putDTDHash
(
String
name
,
DTD
dtd
)
{
dtdHash
.
put
(
name
,
dtd
);
getDtdHash
()
.
put
(
name
,
dtd
);
}
/**
* Returns a DTD with the specified <code>name</code>. If
* a DTD with that name doesn't exist, one is created
...
...
@@ -332,13 +335,27 @@ class DTD implements DTDConstants {
*/
public
static
DTD
getDTD
(
String
name
)
throws
IOException
{
name
=
name
.
toLowerCase
();
DTD
dtd
=
dtdHash
.
get
(
name
);
DTD
dtd
=
getDtdHash
()
.
get
(
name
);
if
(
dtd
==
null
)
dtd
=
new
DTD
(
name
);
return
dtd
;
}
private
static
Hashtable
<
String
,
DTD
>
getDtdHash
()
{
AppContext
appContext
=
AppContext
.
getAppContext
();
Hashtable
<
String
,
DTD
>
result
=
(
Hashtable
<
String
,
DTD
>)
appContext
.
get
(
DTD_HASH_KEY
);
if
(
result
==
null
)
{
result
=
new
Hashtable
<
String
,
DTD
>();
appContext
.
put
(
DTD_HASH_KEY
,
result
);
}
return
result
;
}
/**
* Recreates a DTD from an archived format.
* @param in the <code>DataInputStream</code> to read from
...
...
src/share/classes/javax/swing/text/html/parser/ParserDelegator.java
浏览文件 @
e0bb1cc8
/*
* Copyright (c) 1998, 20
02
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 20
10
, 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
...
...
@@ -25,6 +25,8 @@
package
javax.swing.text.html.parser
;
import
sun.awt.AppContext
;
import
javax.swing.text.html.HTMLEditorKit
;
import
java.io.BufferedInputStream
;
import
java.io.IOException
;
...
...
@@ -33,7 +35,6 @@ import java.io.DataInputStream;
import
java.io.ObjectInputStream
;
import
java.io.Reader
;
import
java.io.Serializable
;
import
java.lang.reflect.Method
;
/**
* Responsible for starting up a new DocumentParser
...
...
@@ -45,9 +46,13 @@ import java.lang.reflect.Method;
public
class
ParserDelegator
extends
HTMLEditorKit
.
Parser
implements
Serializable
{
private
static
DTD
dtd
=
null
;
private
static
final
Object
DTD_KEY
=
new
Object
()
;
protected
static
synchronized
void
setDefaultDTD
()
{
AppContext
appContext
=
AppContext
.
getAppContext
();
DTD
dtd
=
(
DTD
)
appContext
.
get
(
DTD_KEY
);
if
(
dtd
==
null
)
{
DTD
_dtd
=
null
;
// (PENDING) Hate having to hard code!
...
...
@@ -59,6 +64,8 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl
System
.
out
.
println
(
"Throw an exception: could not get default dtd: "
+
nm
);
}
dtd
=
createDTD
(
_dtd
,
nm
);
appContext
.
put
(
DTD_KEY
,
dtd
);
}
}
...
...
@@ -81,13 +88,11 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl
public
ParserDelegator
()
{
if
(
dtd
==
null
)
{
setDefaultDTD
();
}
}
public
void
parse
(
Reader
r
,
HTMLEditorKit
.
ParserCallback
cb
,
boolean
ignoreCharSet
)
throws
IOException
{
new
DocumentParser
(
dtd
).
parse
(
r
,
cb
,
ignoreCharSet
);
new
DocumentParser
(
(
DTD
)
AppContext
.
getAppContext
().
get
(
DTD_KEY
)
).
parse
(
r
,
cb
,
ignoreCharSet
);
}
/**
...
...
@@ -113,8 +118,6 @@ public class ParserDelegator extends HTMLEditorKit.Parser implements Serializabl
private
void
readObject
(
ObjectInputStream
s
)
throws
ClassNotFoundException
,
IOException
{
s
.
defaultReadObject
();
if
(
dtd
==
null
)
{
setDefaultDTD
();
}
}
}
test/javax/swing/Security/6938813/bug6938813.java
0 → 100644
浏览文件 @
e0bb1cc8
/*
* Copyright (c) 2010, 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.
*/
/*
* @test
* @bug 6938813
* @summary Swing mutable statics
* @author Pavel Porvatov
*/
import
sun.awt.AppContext
;
import
sun.awt.SunToolkit
;
import
javax.swing.text.html.HTMLEditorKit
;
import
javax.swing.text.html.StyleSheet
;
import
javax.swing.text.html.parser.DTD
;
import
javax.swing.text.html.parser.ParserDelegator
;
import
java.lang.reflect.Field
;
public
class
bug6938813
{
public
static
final
String
DTD_KEY
=
"dtd_key"
;
private
static
volatile
StyleSheet
styleSheet
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// Run validation and init values for this AppContext
validate
();
Thread
thread
=
new
ThreadInAnotherAppContext
();
thread
.
start
();
thread
.
join
();
}
private
static
void
validate
()
throws
Exception
{
AppContext
appContext
=
AppContext
.
getAppContext
();
assertTrue
(
DTD
.
getDTD
(
DTD_KEY
).
getName
().
equals
(
DTD_KEY
),
"DTD.getDTD() mixed AppContexts"
);
// Spoil hash value
DTD
invalidDtd
=
DTD
.
getDTD
(
"invalid DTD"
);
DTD
.
putDTDHash
(
DTD_KEY
,
invalidDtd
);
assertTrue
(
DTD
.
getDTD
(
DTD_KEY
)
==
invalidDtd
,
"Something wrong with DTD.getDTD()"
);
Object
dtdKey
=
getParserDelegator_DTD_KEY
();
assertTrue
(
appContext
.
get
(
dtdKey
)
==
null
,
"ParserDelegator mixed AppContexts"
);
// Init default DTD
new
ParserDelegator
();
Object
dtdValue
=
appContext
.
get
(
dtdKey
);
assertTrue
(
dtdValue
!=
null
,
"ParserDelegator.defaultDTD isn't initialized"
);
// Try reinit default DTD
new
ParserDelegator
();
assertTrue
(
dtdValue
==
appContext
.
get
(
dtdKey
),
"ParserDelegator.defaultDTD created a duplicate"
);
HTMLEditorKit
htmlEditorKit
=
new
HTMLEditorKit
();
if
(
styleSheet
==
null
)
{
// First AppContext
styleSheet
=
htmlEditorKit
.
getStyleSheet
();
assertTrue
(
styleSheet
!=
null
,
"htmlEditorKit.getStyleSheet() returns null"
);
assertTrue
(
htmlEditorKit
.
getStyleSheet
()
==
styleSheet
,
"Something wrong with htmlEditorKit.getStyleSheet()"
);
}
else
{
assertTrue
(
htmlEditorKit
.
getStyleSheet
()
!=
styleSheet
,
"HtmlEditorKit.getStyleSheet() mixed AppContexts"
);
}
}
private
static
void
assertTrue
(
boolean
b
,
String
msg
)
{
if
(!
b
)
{
throw
new
RuntimeException
(
"Test failed: "
+
msg
);
}
}
private
static
Object
getParserDelegator_DTD_KEY
()
throws
Exception
{
Field
field
=
ParserDelegator
.
class
.
getDeclaredField
(
"DTD_KEY"
);
field
.
setAccessible
(
true
);
return
field
.
get
(
null
);
}
private
static
class
ThreadInAnotherAppContext
extends
Thread
{
public
ThreadInAnotherAppContext
()
{
super
(
new
ThreadGroup
(
"6938813"
),
"ThreadInAnotherAppContext"
);
}
public
void
run
()
{
SunToolkit
.
createNewAppContext
();
try
{
validate
();
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录