Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
c6f27a8e
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看板
提交
c6f27a8e
编写于
4月 10, 2012
作者:
R
rupashka
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7146146: Deadlock between subclass of AbstractDocument and UndoManager
Reviewed-by: art
上级
9b08f10f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
119 addition
and
15 deletion
+119
-15
src/share/classes/javax/swing/text/AbstractDocument.java
src/share/classes/javax/swing/text/AbstractDocument.java
+42
-15
test/javax/swing/text/AbstractDocument/7146146/bug7146146.java
...javax/swing/text/AbstractDocument/7146146/bug7146146.java
+77
-0
未找到文件。
src/share/classes/javax/swing/text/AbstractDocument.java
浏览文件 @
c6f27a8e
...
...
@@ -31,7 +31,6 @@ import java.text.Bidi;
import
javax.swing.UIManager
;
import
javax.swing.undo.*
;
import
javax.swing.event.ChangeListener
;
import
javax.swing.event.*
;
import
javax.swing.tree.TreeNode
;
...
...
@@ -698,28 +697,31 @@ public abstract class AbstractDocument implements Document, Serializable {
return
;
}
DocumentFilter
filter
=
getDocumentFilter
();
InsertStringResult
insertStringResult
=
null
;
writeLock
();
try
{
if
(
filter
!=
null
)
{
filter
.
insertString
(
getFilterBypass
(),
offs
,
str
,
a
);
}
else
{
handleInsertString
(
offs
,
str
,
a
);
}
else
{
insertStringResult
=
handleInsertString
(
offs
,
str
,
a
);
}
}
finally
{
writeUnlock
();
}
processInsertStringResult
(
insertStringResult
);
}
/**
* Performs the actual work of inserting the text; it is assumed the
* caller has obtained a write lock before invoking this.
*/
void
handleInsertString
(
int
offs
,
String
str
,
AttributeSet
a
)
throws
BadLocationException
{
private
InsertStringResult
handleInsertString
(
int
offs
,
String
str
,
AttributeSet
a
)
throws
BadLocationException
{
if
((
str
==
null
)
||
(
str
.
length
()
==
0
))
{
return
;
return
null
;
}
UndoableEdit
u
=
data
.
insertString
(
offs
,
str
);
DefaultDocumentEvent
e
=
...
...
@@ -746,12 +748,29 @@ public abstract class AbstractDocument implements Document, Serializable {
insertUpdate
(
e
,
a
);
// Mark the edit as done.
e
.
end
();
fireInsertUpdate
(
e
);
InsertStringResult
result
=
new
InsertStringResult
();
result
.
documentEvent
=
e
;
// only fire undo if Content implementation supports it
// undo for the composed text is not supported for now
if
(
u
!=
null
&&
(
a
==
null
||
!
a
.
isDefined
(
StyleConstants
.
ComposedTextAttribute
)))
{
fireUndoableEditUpdate
(
new
UndoableEditEvent
(
this
,
e
));
if
(
u
!=
null
&&
(
a
==
null
||
!
a
.
isDefined
(
StyleConstants
.
ComposedTextAttribute
)))
{
result
.
undoableEditEvent
=
new
UndoableEditEvent
(
this
,
e
);
}
return
result
;
}
private
void
processInsertStringResult
(
InsertStringResult
insertStringResult
)
{
if
(
insertStringResult
==
null
)
{
return
;
}
fireInsertUpdate
(
insertStringResult
.
documentEvent
);
if
(
insertStringResult
.
undoableEditEvent
!=
null
)
{
fireUndoableEditUpdate
(
insertStringResult
.
undoableEditEvent
);
}
}
...
...
@@ -2947,12 +2966,10 @@ public abstract class AbstractDocument implements Document, Serializable {
*/
class
UndoRedoDocumentEvent
implements
DocumentEvent
{
private
DefaultDocumentEvent
src
=
null
;
private
boolean
isUndo
;
private
EventType
type
=
null
;
public
UndoRedoDocumentEvent
(
DefaultDocumentEvent
src
,
boolean
isUndo
)
{
this
.
src
=
src
;
this
.
isUndo
=
isUndo
;
if
(
isUndo
)
{
if
(
src
.
getType
().
equals
(
EventType
.
INSERT
))
{
type
=
EventType
.
REMOVE
;
...
...
@@ -3106,13 +3123,23 @@ public abstract class AbstractDocument implements Document, Serializable {
public
void
insertString
(
int
offset
,
String
string
,
AttributeSet
attr
)
throws
BadLocationException
{
handleInsertString
(
offset
,
string
,
attr
);
InsertStringResult
insertStringResult
=
handleInsertString
(
offset
,
string
,
attr
);
processInsertStringResult
(
insertStringResult
);
}
public
void
replace
(
int
offset
,
int
length
,
String
text
,
AttributeSet
attrs
)
throws
BadLocationException
{
handleRemove
(
offset
,
length
);
handleInsertString
(
offset
,
text
,
attrs
);
InsertStringResult
insertStringResult
=
handleInsertString
(
offset
,
text
,
attrs
);
processInsertStringResult
(
insertStringResult
);
}
}
private
static
class
InsertStringResult
{
DefaultDocumentEvent
documentEvent
;
UndoableEditEvent
undoableEditEvent
;
}
}
test/javax/swing/text/AbstractDocument/7146146/bug7146146.java
0 → 100644
浏览文件 @
c6f27a8e
/*
* Copyright (c) 2012, 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 7146146
@summary Deadlock between subclass of AbstractDocument and UndoManager
@author Pavel Porvatov
*/
import
javax.swing.text.BadLocationException
;
import
javax.swing.text.PlainDocument
;
import
javax.swing.text.StringContent
;
import
javax.swing.undo.UndoManager
;
public
class
bug7146146
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
System
.
out
.
print
(
"Iteration "
+
i
);
test
();
System
.
out
.
print
(
" passed"
);
}
}
private
static
void
test
()
throws
Exception
{
final
PlainDocument
doc
=
new
PlainDocument
(
new
StringContent
());
final
UndoManager
undoManager
=
new
UndoManager
();
doc
.
addUndoableEditListener
(
undoManager
);
doc
.
insertString
(
0
,
"<Test 1>"
,
null
);
Thread
t1
=
new
Thread
(
"Thread 1"
)
{
@Override
public
void
run
()
{
try
{
doc
.
insertString
(
0
,
"<Test 2>"
,
null
);
}
catch
(
BadLocationException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
};
Thread
t2
=
new
Thread
(
"Thread 2"
)
{
@Override
public
void
run
()
{
undoManager
.
undo
();
}
};
t1
.
start
();
t2
.
start
();
t1
.
join
();
t2
.
join
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录