Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
f9a1bf8c
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看板
提交
f9a1bf8c
编写于
12月 23, 2013
作者:
M
malenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8030118: Document listeners fired outside document lock
Reviewed-by: art, serb
上级
23bd4b84
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
90 addition
and
38 deletion
+90
-38
src/share/classes/javax/swing/text/AbstractDocument.java
src/share/classes/javax/swing/text/AbstractDocument.java
+7
-38
test/javax/swing/text/AbstractDocument/8030118/Test8030118.java
...avax/swing/text/AbstractDocument/8030118/Test8030118.java
+83
-0
未找到文件。
src/share/classes/javax/swing/text/AbstractDocument.java
浏览文件 @
f9a1bf8c
...
@@ -697,7 +697,6 @@ public abstract class AbstractDocument implements Document, Serializable {
...
@@ -697,7 +697,6 @@ public abstract class AbstractDocument implements Document, Serializable {
return
;
return
;
}
}
DocumentFilter
filter
=
getDocumentFilter
();
DocumentFilter
filter
=
getDocumentFilter
();
InsertStringResult
insertStringResult
=
null
;
writeLock
();
writeLock
();
...
@@ -705,23 +704,21 @@ public abstract class AbstractDocument implements Document, Serializable {
...
@@ -705,23 +704,21 @@ public abstract class AbstractDocument implements Document, Serializable {
if
(
filter
!=
null
)
{
if
(
filter
!=
null
)
{
filter
.
insertString
(
getFilterBypass
(),
offs
,
str
,
a
);
filter
.
insertString
(
getFilterBypass
(),
offs
,
str
,
a
);
}
else
{
}
else
{
insertStringResult
=
handleInsertString
(
offs
,
str
,
a
);
handleInsertString
(
offs
,
str
,
a
);
}
}
}
finally
{
}
finally
{
writeUnlock
();
writeUnlock
();
}
}
processInsertStringResult
(
insertStringResult
);
}
}
/**
/**
* Performs the actual work of inserting the text; it is assumed the
* Performs the actual work of inserting the text; it is assumed the
* caller has obtained a write lock before invoking this.
* caller has obtained a write lock before invoking this.
*/
*/
private
InsertStringResult
handleInsertString
(
int
offs
,
String
str
,
AttributeSet
a
)
private
void
handleInsertString
(
int
offs
,
String
str
,
AttributeSet
a
)
throws
BadLocationException
{
throws
BadLocationException
{
if
((
str
==
null
)
||
(
str
.
length
()
==
0
))
{
if
((
str
==
null
)
||
(
str
.
length
()
==
0
))
{
return
null
;
return
;
}
}
UndoableEdit
u
=
data
.
insertString
(
offs
,
str
);
UndoableEdit
u
=
data
.
insertString
(
offs
,
str
);
DefaultDocumentEvent
e
=
DefaultDocumentEvent
e
=
...
@@ -748,29 +745,11 @@ public abstract class AbstractDocument implements Document, Serializable {
...
@@ -748,29 +745,11 @@ public abstract class AbstractDocument implements Document, Serializable {
insertUpdate
(
e
,
a
);
insertUpdate
(
e
,
a
);
// Mark the edit as done.
// Mark the edit as done.
e
.
end
();
e
.
end
();
fireInsertUpdate
(
e
);
InsertStringResult
result
=
new
InsertStringResult
();
result
.
documentEvent
=
e
;
// only fire undo if Content implementation supports it
// only fire undo if Content implementation supports it
// undo for the composed text is not supported for now
// undo for the composed text is not supported for now
if
(
u
!=
null
&&
(
a
==
null
||
!
a
.
isDefined
(
StyleConstants
.
ComposedTextAttribute
)))
{
if
(
u
!=
null
&&
(
a
==
null
||
!
a
.
isDefined
(
StyleConstants
.
ComposedTextAttribute
)))
{
result
.
undoableEditEvent
=
new
UndoableEditEvent
(
this
,
e
);
fireUndoableEditUpdate
(
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
);
}
}
}
}
...
@@ -3125,23 +3104,13 @@ public abstract class AbstractDocument implements Document, Serializable {
...
@@ -3125,23 +3104,13 @@ public abstract class AbstractDocument implements Document, Serializable {
public
void
insertString
(
int
offset
,
String
string
,
public
void
insertString
(
int
offset
,
String
string
,
AttributeSet
attr
)
throws
AttributeSet
attr
)
throws
BadLocationException
{
BadLocationException
{
InsertStringResult
insertStringResult
=
handleInsertString
(
offset
,
string
,
attr
);
handleInsertString
(
offset
,
string
,
attr
);
processInsertStringResult
(
insertStringResult
);
}
}
public
void
replace
(
int
offset
,
int
length
,
String
text
,
public
void
replace
(
int
offset
,
int
length
,
String
text
,
AttributeSet
attrs
)
throws
BadLocationException
{
AttributeSet
attrs
)
throws
BadLocationException
{
handleRemove
(
offset
,
length
);
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
→
test/javax/swing/text/AbstractDocument/
8030118/Test8030118
.java
浏览文件 @
f9a1bf8c
/*
/*
* Copyright (c) 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -21,57 +21,63 @@
...
@@ -21,57 +21,63 @@
* questions.
* questions.
*/
*/
/* @test
import
javax.swing.event.DocumentEvent
;
@bug 7146146
import
javax.swing.event.DocumentListener
;
@summary Deadlock between subclass of AbstractDocument and UndoManager
@author Pavel Porvatov
*/
import
javax.swing.text.BadLocationException
;
import
javax.swing.text.BadLocationException
;
import
javax.swing.text.PlainDocument
;
import
javax.swing.text.PlainDocument
;
import
java
x.swing.text.StringContent
;
import
java
.util.concurrent.CountDownLatch
;
import
java
x.swing.undo.UndoManager
;
import
java
.util.concurrent.TimeUnit
;
public
class
bug7146146
{
/*
public
static
void
main
(
String
[]
args
)
throws
Exception
{
* @test
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
* @bug 8030118
System
.
out
.
print
(
"Iteration "
+
i
);
* @summary Tests that AbstractDocument cannot be modified from another thread
* @author Sergey Malenkov
*/
test
();
public
class
Test8030118
implements
DocumentListener
,
Runnable
{
private
final
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
private
final
PlainDocument
doc
=
new
PlainDocument
();
System
.
out
.
print
(
" passed"
);
private
Test8030118
(
String
string
)
throws
Exception
{
}
this
.
doc
.
addDocumentListener
(
this
);
this
.
doc
.
insertString
(
0
,
string
,
null
);
}
}
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
@Override
public
void
run
()
{
public
void
run
()
{
try
{
try
{
doc
.
insertString
(
0
,
"<Test 2>"
,
null
);
this
.
doc
.
remove
(
0
,
this
.
doc
.
getLength
()
);
}
catch
(
BadLocationException
e
)
{
}
catch
(
BadLocationException
exception
)
{
throw
new
RuntimeException
(
e
);
throw
new
Error
(
"unexpected"
,
exception
);
}
}
this
.
latch
.
countDown
();
}
}
};
Thread
t2
=
new
Thread
(
"Thread 2"
)
{
@Override
@Override
public
void
run
()
{
public
void
insertUpdate
(
DocumentEvent
event
)
{
undoManager
.
undo
();
new
Thread
(
this
).
start
();
try
{
this
.
latch
.
await
(
10
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
exception
)
{
throw
new
Error
(
"unexpected"
,
exception
);
}
try
{
event
.
getDocument
().
getText
(
event
.
getOffset
(),
event
.
getLength
());
}
catch
(
BadLocationException
exception
)
{
throw
new
Error
(
"concurrent modification"
,
exception
);
}
}
}
};
t1
.
start
();
@Override
t2
.
start
();
public
void
removeUpdate
(
DocumentEvent
event
)
{
}
t1
.
join
();
@Override
t2
.
join
();
public
void
changedUpdate
(
DocumentEvent
event
)
{
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
Test8030118
(
"string"
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录