Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
c4a40797
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看板
提交
c4a40797
编写于
3月 04, 2010
作者:
M
malenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6921644: XMLEncoder generates invalid XML
Reviewed-by: peterz
上级
762950e4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
453 addition
and
34 deletion
+453
-34
src/share/classes/java/beans/XMLEncoder.java
src/share/classes/java/beans/XMLEncoder.java
+35
-34
test/java/beans/XMLEncoder/Test5023550.java
test/java/beans/XMLEncoder/Test5023550.java
+122
-0
test/java/beans/XMLEncoder/Test5023557.java
test/java/beans/XMLEncoder/Test5023557.java
+99
-0
test/java/beans/XMLEncoder/Test6921644.java
test/java/beans/XMLEncoder/Test6921644.java
+197
-0
未找到文件。
src/share/classes/java/beans/XMLEncoder.java
浏览文件 @
c4a40797
/*
* Copyright 2000-20
06
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2000-20
10
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
...
...
@@ -214,8 +214,8 @@ public class XMLEncoder extends Encoder {
private
Object
owner
;
private
int
indentation
=
0
;
private
boolean
internal
=
false
;
private
Map
valueToExpression
;
private
Map
targetToStatementList
;
private
Map
<
Object
,
ValueData
>
valueToExpression
;
private
Map
<
Object
,
List
<
Statement
>>
targetToStatementList
;
private
boolean
preambleWritten
=
false
;
private
NameGenerator
nameGenerator
;
...
...
@@ -287,8 +287,8 @@ public class XMLEncoder extends Encoder {
this
.
declaration
=
declaration
;
this
.
indentation
=
indentation
;
this
.
out
=
new
OutputStreamWriter
(
out
,
cs
.
newEncoder
());
valueToExpression
=
new
IdentityHashMap
();
targetToStatementList
=
new
IdentityHashMap
();
valueToExpression
=
new
IdentityHashMap
<
Object
,
ValueData
>
();
targetToStatementList
=
new
IdentityHashMap
<
Object
,
List
<
Statement
>>
();
nameGenerator
=
new
NameGenerator
();
}
...
...
@@ -331,13 +331,12 @@ public class XMLEncoder extends Encoder {
}
}
private
Vector
statementList
(
Object
target
)
{
Vector
list
=
(
Vector
)
targetToStatementList
.
get
(
target
);
if
(
list
!=
null
)
{
return
list
;
private
List
<
Statement
>
statementList
(
Object
target
)
{
List
<
Statement
>
list
=
targetToStatementList
.
get
(
target
);
if
(
list
==
null
)
{
list
=
new
ArrayList
<
Statement
>();
targetToStatementList
.
put
(
target
,
list
);
}
list
=
new
Vector
();
targetToStatementList
.
put
(
target
,
list
);
return
list
;
}
...
...
@@ -363,13 +362,13 @@ public class XMLEncoder extends Encoder {
}
d
.
marked
=
true
;
Object
target
=
exp
.
getTarget
();
mark
(
exp
);
if
(!(
target
instanceof
Class
))
{
statementList
(
target
).
add
(
exp
);
// Pending: Why does the reference count need to
// be incremented here?
d
.
refs
++;
}
mark
(
exp
);
}
private
void
mark
(
Statement
stm
)
{
...
...
@@ -463,9 +462,9 @@ public class XMLEncoder extends Encoder {
preambleWritten
=
true
;
}
indentation
++;
Vector
roo
ts
=
statementList
(
this
);
for
(
int
i
=
0
;
i
<
roots
.
size
();
i
++
)
{
Statement
s
=
(
Statement
)
roots
.
get
(
i
);
List
<
Statement
>
statemen
ts
=
statementList
(
this
);
while
(!
statements
.
isEmpty
()
)
{
Statement
s
=
statements
.
remove
(
0
);
if
(
"writeObject"
.
equals
(
s
.
getMethodName
()))
{
outputValue
(
s
.
getArguments
()[
0
],
this
,
true
);
}
...
...
@@ -513,7 +512,7 @@ public class XMLEncoder extends Encoder {
}
private
ValueData
getValueData
(
Object
o
)
{
ValueData
d
=
(
ValueData
)
valueToExpression
.
get
(
o
);
ValueData
d
=
valueToExpression
.
get
(
o
);
if
(
d
==
null
)
{
d
=
new
ValueData
();
valueToExpression
.
put
(
o
,
d
);
...
...
@@ -619,11 +618,11 @@ public class XMLEncoder extends Encoder {
}
if
(
d
.
name
!=
null
)
{
writeln
(
"<object idref="
+
quote
(
d
.
name
)
+
"/>"
);
return
;
outputXML
(
isArgument
?
"object"
:
"void"
,
" idref="
+
quote
(
d
.
name
),
value
);
}
else
if
(
d
.
exp
!=
null
)
{
outputStatement
(
d
.
exp
,
outer
,
isArgument
);
}
outputStatement
(
d
.
exp
,
outer
,
isArgument
);
}
private
static
String
quoteCharCode
(
int
code
)
{
...
...
@@ -683,13 +682,6 @@ public class XMLEncoder extends Encoder {
String
tag
=
(
expression
&&
isArgument
)
?
"object"
:
"void"
;
String
attributes
=
""
;
ValueData
d
=
getValueData
(
value
);
if
(
expression
)
{
if
(
d
.
refs
>
1
)
{
String
instanceName
=
nameGenerator
.
instanceName
(
value
);
d
.
name
=
instanceName
;
attributes
=
attributes
+
" id="
+
quote
(
instanceName
);
}
}
// Special cases for targets.
if
(
target
==
outer
)
{
...
...
@@ -706,13 +698,19 @@ public class XMLEncoder extends Encoder {
else
{
d
.
refs
=
2
;
getValueData
(
target
).
refs
++;
outputValue
(
target
,
outer
,
false
);
if
(
isArgument
)
{
outputValue
(
value
,
outer
,
false
);
List
<
Statement
>
statements
=
statementList
(
target
);
if
(
!
statements
.
contains
(
exp
)
)
{
statements
.
add
(
exp
);
}
outputValue
(
target
,
outer
,
false
);
outputValue
(
value
,
outer
,
isArgument
);
return
;
}
if
(
expression
&&
(
d
.
refs
>
1
))
{
String
instanceName
=
nameGenerator
.
instanceName
(
value
);
d
.
name
=
instanceName
;
attributes
=
attributes
+
" id="
+
quote
(
instanceName
);
}
// Special cases for methods.
if
((!
expression
&&
methodName
.
equals
(
"set"
)
&&
args
.
length
==
2
&&
...
...
@@ -730,8 +728,11 @@ public class XMLEncoder extends Encoder {
else
if
(!
methodName
.
equals
(
"new"
)
&&
!
methodName
.
equals
(
"newInstance"
))
{
attributes
=
attributes
+
" method="
+
quote
(
methodName
);
}
outputXML
(
tag
,
attributes
,
value
,
args
);
}
Vector
statements
=
statementList
(
value
);
private
void
outputXML
(
String
tag
,
String
attributes
,
Object
value
,
Object
...
args
)
{
List
<
Statement
>
statements
=
statementList
(
value
);
// Use XML's short form when there is no body.
if
(
args
.
length
==
0
&&
statements
.
size
()
==
0
)
{
writeln
(
"<"
+
tag
+
attributes
+
"/>"
);
...
...
@@ -745,8 +746,8 @@ public class XMLEncoder extends Encoder {
outputValue
(
args
[
i
],
null
,
true
);
}
for
(
int
i
=
0
;
i
<
statements
.
size
();
i
++
)
{
Statement
s
=
(
Statement
)
statements
.
get
(
i
);
while
(!
statements
.
isEmpty
()
)
{
Statement
s
=
statements
.
remove
(
0
);
outputStatement
(
s
,
value
,
false
);
}
...
...
test/java/beans/XMLEncoder/Test5023550.java
0 → 100644
浏览文件 @
c4a40797
/*
* Copyright 2010 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 5023550
* @summary Tests complex references to owner
* @author Sergey Malenkov
*/
import
java.beans.DefaultPersistenceDelegate
;
import
java.beans.Encoder
;
import
java.beans.Expression
;
import
java.beans.XMLDecoder
;
import
java.beans.XMLEncoder
;
public
class
Test5023550
extends
AbstractTest
{
public
static
void
main
(
String
[]
args
)
{
new
Test5023550
().
test
(
true
);
}
private
final
Owner
owner
=
new
Owner
();
@Override
protected
void
initialize
(
XMLEncoder
encoder
)
{
encoder
.
setOwner
(
this
.
owner
);
encoder
.
setPersistenceDelegate
(
A
.
class
,
new
ADelegate
());
encoder
.
setPersistenceDelegate
(
B
.
class
,
new
BDelegate
());
encoder
.
setPersistenceDelegate
(
C
.
class
,
new
CDelegate
());
}
@Override
protected
void
initialize
(
XMLDecoder
decoder
)
{
decoder
.
setOwner
(
this
.
owner
);
}
protected
Object
getObject
()
{
return
this
.
owner
.
newA
(
this
.
owner
.
newB
().
newC
());
}
public
static
class
Owner
{
public
A
newA
(
C
c
)
{
return
new
A
(
c
);
}
public
B
newB
()
{
return
new
B
();
}
}
public
static
class
A
{
private
final
C
c
;
private
A
(
C
c
)
{
this
.
c
=
c
;
}
public
C
getC
()
{
return
this
.
c
;
}
}
public
static
class
B
{
public
C
newC
()
{
return
new
C
(
this
);
}
}
public
static
class
C
{
private
final
B
b
;
private
C
(
B
b
)
{
this
.
b
=
b
;
}
public
B
getB
()
{
return
this
.
b
;
}
}
public
static
class
ADelegate
extends
DefaultPersistenceDelegate
{
protected
Expression
instantiate
(
Object
old
,
Encoder
out
)
{
XMLEncoder
encoder
=
(
XMLEncoder
)
out
;
A
a
=
(
A
)
old
;
return
new
Expression
(
old
,
encoder
.
getOwner
(),
"newA"
,
new
Object
[]
{
a
.
getC
()
});
}
}
public
static
class
BDelegate
extends
DefaultPersistenceDelegate
{
protected
Expression
instantiate
(
Object
old
,
Encoder
out
)
{
XMLEncoder
encoder
=
(
XMLEncoder
)
out
;
return
new
Expression
(
old
,
encoder
.
getOwner
(),
"newB"
,
new
Object
[
0
]);
}
}
public
static
class
CDelegate
extends
DefaultPersistenceDelegate
{
protected
Expression
instantiate
(
Object
old
,
Encoder
out
)
{
C
c
=
(
C
)
old
;
return
new
Expression
(
c
,
c
.
getB
(),
"newC"
,
new
Object
[
0
]);
}
}
}
test/java/beans/XMLEncoder/Test5023557.java
0 → 100644
浏览文件 @
c4a40797
/*
* Copyright 2010 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 5023557
* @summary Tests complex references
* @author Sergey Malenkov
*/
import
java.beans.DefaultPersistenceDelegate
;
import
java.beans.Encoder
;
import
java.beans.Expression
;
import
java.beans.XMLEncoder
;
public
class
Test5023557
extends
AbstractTest
{
public
static
void
main
(
String
[]
args
)
{
new
Test5023557
().
test
(
true
);
}
@Override
protected
void
initialize
(
XMLEncoder
encoder
)
{
encoder
.
setPersistenceDelegate
(
B
.
class
,
new
BDelegate
());
encoder
.
setPersistenceDelegate
(
C
.
class
,
new
CDelegate
());
}
protected
Object
getObject
()
{
A
a
=
new
A
();
return
a
.
newC
(
a
.
newB
());
}
public
static
class
A
{
public
B
newB
()
{
return
new
B
(
this
);
}
public
C
newC
(
B
b
)
{
return
new
C
(
b
);
}
}
public
static
class
B
{
private
final
A
a
;
private
B
(
A
a
)
{
this
.
a
=
a
;
}
public
A
getA
()
{
return
this
.
a
;
}
}
public
static
class
C
{
private
final
B
b
;
private
C
(
B
b
)
{
this
.
b
=
b
;
}
public
B
getB
()
{
return
this
.
b
;
}
}
public
static
class
BDelegate
extends
DefaultPersistenceDelegate
{
protected
Expression
instantiate
(
Object
old
,
Encoder
out
)
{
B
b
=
(
B
)
old
;
return
new
Expression
(
b
,
b
.
getA
(),
"newB"
,
new
Object
[
0
]);
}
}
public
static
class
CDelegate
extends
DefaultPersistenceDelegate
{
protected
Expression
instantiate
(
Object
old
,
Encoder
out
)
{
C
c
=
(
C
)
old
;
return
new
Expression
(
c
,
c
.
getB
().
getA
(),
"newC"
,
new
Object
[]
{
c
.
getB
()
});
}
}
}
test/java/beans/XMLEncoder/Test6921644.java
0 → 100644
浏览文件 @
c4a40797
/*
* Copyright 2010 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 6921644
* @summary Tests references to cached integer
* @author Sergey Malenkov
*/
import
java.beans.ConstructorProperties
;
import
java.util.ArrayList
;
import
java.util.List
;
public
final
class
Test6921644
extends
AbstractTest
{
public
static
void
main
(
String
[]
args
)
{
new
Test6921644
().
test
(
true
);
}
protected
Object
getObject
()
{
Owner
<
Author
>
o
=
new
Owner
<
Author
>(
100
);
// it works if ID >= 128
Category
c
=
new
Category
(
o
);
Document
d1
=
new
Document
(
o
);
Document
d2
=
new
Document
(
o
);
Document
d3
=
new
Document
(
o
);
Author
a1
=
new
Author
(
o
);
Author
a2
=
new
Author
(
o
);
Author
a3
=
new
Author
(
o
);
o
.
getList
().
add
(
a1
);
o
.
getList
().
add
(
a2
);
o
.
getList
().
add
(
a3
);
a3
.
setRef
(
o
.
getId
());
d2
.
setCategory
(
c
);
d3
.
setCategory
(
c
);
a1
.
addDocument
(
d1
);
a1
.
addDocument
(
d2
);
a3
.
addDocument
(
d3
);
c
.
addDocument
(
d2
);
c
.
addDocument
(
d3
);
return
o
;
}
public
static
class
Owner
<
T
>
{
private
int
id
;
private
List
<
T
>
list
=
new
ArrayList
<
T
>();
@ConstructorProperties
(
"id"
)
public
Owner
(
int
id
)
{
this
.
id
=
id
;
}
public
int
getId
()
{
return
this
.
id
;
}
public
List
<
T
>
getList
()
{
return
this
.
list
;
}
public
void
setList
(
List
<
T
>
list
)
{
this
.
list
=
list
;
}
}
public
static
class
Author
{
private
int
id
;
private
int
ref
;
private
Owner
owner
;
private
List
<
Document
>
list
=
new
ArrayList
<
Document
>();
@ConstructorProperties
(
"owner"
)
public
Author
(
Owner
<
Author
>
owner
)
{
this
.
owner
=
owner
;
this
.
id
=
owner
.
getId
();
}
public
Owner
getOwner
()
{
return
this
.
owner
;
}
public
Integer
getId
()
{
return
this
.
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Integer
getRef
()
{
return
this
.
ref
;
}
public
void
setRef
(
Integer
ref
)
{
this
.
ref
=
ref
;
}
public
List
<
Document
>
getList
()
{
return
this
.
list
;
}
public
void
setList
(
List
<
Document
>
list
)
{
this
.
list
=
list
;
}
public
void
addDocument
(
Document
document
)
{
this
.
list
.
add
(
document
);
document
.
setAuthor
(
this
);
}
}
public
static
class
Category
{
private
Owner
owner
;
private
List
<
Document
>
list
=
new
ArrayList
<
Document
>();
@ConstructorProperties
(
"owner"
)
public
Category
(
Owner
owner
)
{
this
.
owner
=
owner
;
}
public
Owner
getOwner
()
{
return
this
.
owner
;
}
public
List
<
Document
>
getList
()
{
return
this
.
list
;
}
public
void
setList
(
List
<
Document
>
list
)
{
this
.
list
=
list
;
}
public
void
addDocument
(
Document
document
)
{
this
.
list
.
add
(
document
);
document
.
setCategory
(
this
);
}
}
public
static
class
Document
{
private
Owner
owner
;
private
Author
author
;
private
Category
category
;
@ConstructorProperties
(
"owner"
)
public
Document
(
Owner
owner
)
{
this
.
owner
=
owner
;
}
public
Owner
getOwner
()
{
return
this
.
owner
;
}
public
Author
getAuthor
()
{
return
this
.
author
;
}
public
void
setAuthor
(
Author
author
)
{
this
.
author
=
author
;
}
public
Category
getCategory
()
{
return
this
.
category
;
}
public
void
setCategory
(
Category
category
)
{
this
.
category
=
category
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录