Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
beda5993
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看板
提交
beda5993
编写于
3月 24, 2016
作者:
A
aefimov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8145039: JAXB marshaller fails with ClassCastException on classes generated by xjc
Reviewed-by: lancea
上级
4bcc4a2f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
180 addition
and
1 deletion
+180
-1
test/TEST.groups
test/TEST.groups
+2
-1
test/javax/xml/bind/xjc/8145039/JaxbMarshallTest.java
test/javax/xml/bind/xjc/8145039/JaxbMarshallTest.java
+157
-0
test/javax/xml/bind/xjc/8145039/testSchema.xsd
test/javax/xml/bind/xjc/8145039/testSchema.xsd
+21
-0
未找到文件。
test/TEST.groups
浏览文件 @
beda5993
...
...
@@ -352,7 +352,8 @@ needs_jdk = \
javax/xml/bind/jxc \
javax/xml/ws/8033113 \
javax/xml/ws/clientjar/TestWsImport.java \
javax/xml/ws/ebcdic
javax/xml/ws/ebcdic \
javax/xml/bind/xjc/8145039/JaxbMarshallTest.java
# JRE adds further tests to compact3
#
...
...
test/javax/xml/bind/xjc/8145039/JaxbMarshallTest.java
0 → 100644
浏览文件 @
beda5993
/*
* Copyright (c) 2016, 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 8145039
* @summary Check that marshalling of xjc generated class doesn't throw
* ClassCast exception.
* @library /lib/testlibrary
* @run testng/othervm JaxbMarshallTest
*/
import
java.io.IOException
;
import
java.lang.reflect.Method
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
static
java
.
nio
.
file
.
StandardCopyOption
.
REPLACE_EXISTING
;
import
java.util.Arrays
;
import
java.util.List
;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.Marshaller
;
import
jdk.testlibrary.JDKToolLauncher
;
import
org.testng.annotations.BeforeTest
;
import
org.testng.annotations.Test
;
public
class
JaxbMarshallTest
{
@BeforeTest
public
void
setUp
()
throws
IOException
{
// Create test directory inside scratch
testWorkDir
=
Paths
.
get
(
System
.
getProperty
(
"user.dir"
,
"."
));
// Save its URL
testWorkDirUrl
=
testWorkDir
.
toUri
().
toURL
();
// Get test source directory path
testSrcDir
=
Paths
.
get
(
System
.
getProperty
(
"test.src"
,
"."
));
// Get path of xjc result folder
xjcResultDir
=
testWorkDir
.
resolve
(
TEST_PACKAGE
);
// Copy schema document file to scratch directory
Files
.
copy
(
testSrcDir
.
resolve
(
XSD_FILENAME
),
testWorkDir
.
resolve
(
XSD_FILENAME
),
REPLACE_EXISTING
);
}
/*
* Test does the following steps to reproduce problem reported by 8145039:
* 1. Copy test schema to JTREG scratch folder
* 2. Run xjc on test schema file
* 3. Compile generated java files with test javac
* 4. Marshall the new list instance to ensure that
* ClassCastException is not thrown
*/
@Test
public
void
marshallClassCastExceptionTest
()
throws
Exception
{
JAXBContext
jaxbContext
;
Marshaller
marshaller
;
URLClassLoader
jaxbContextClassLoader
;
// Generate java classes by xjc
runXjc
(
XSD_FILENAME
);
// Compile xjc generated java files
compileXjcGeneratedClasses
();
// Create JAXB context based on xjc generated package.
// Need to create URL class loader ot make compiled classes discoverable
// by JAXB context
jaxbContextClassLoader
=
URLClassLoader
.
newInstance
(
new
URL
[]
{
testWorkDirUrl
});
jaxbContext
=
JAXBContext
.
newInstance
(
TEST_PACKAGE
,
jaxbContextClassLoader
);
// Create instance of Xjc generated data type.
// Java classes were compiled during the test execution hence reflection
// is needed here
Class
classLongListClass
=
jaxbContextClassLoader
.
loadClass
(
TEST_CLASS
);
Object
objectLongListClass
=
classLongListClass
.
newInstance
();
// Get 'getIn' method object
Method
getInMethod
=
classLongListClass
.
getMethod
(
GET_LIST_METHOD
,
(
Class
[])
null
);
// Invoke 'getIn' method
List
<
Long
>
inList
=
(
List
<
Long
>)
getInMethod
.
invoke
(
objectLongListClass
);
// Add values into the jaxb object list
inList
.
add
(
Long
.
valueOf
(
0
));
inList
.
add
(
Long
.
valueOf
(
43
));
inList
.
add
(
Long
.
valueOf
(
1000000123
));
// Marshall constructed complex type variable to standard output.
// In case of failure the ClassCastException will be thrown
marshaller
=
jaxbContext
.
createMarshaller
();
marshaller
.
setProperty
(
Marshaller
.
JAXB_FORMATTED_OUTPUT
,
true
);
marshaller
.
marshal
(
objectLongListClass
,
System
.
out
);
}
// Compile schema file into java classes definitions
void
runXjc
(
String
xsdFileName
)
throws
Exception
{
// Prepare process builder to run schemagen tool and save its output
JDKToolLauncher
xjcLauncher
=
JDKToolLauncher
.
createUsingTestJDK
(
"xjc"
);
xjcLauncher
.
addToolArg
(
xsdFileName
);
System
.
out
.
println
(
"Executing xjc command: "
+
Arrays
.
asList
(
xjcLauncher
.
getCommand
()));
ProcessBuilder
pb
=
new
ProcessBuilder
(
xjcLauncher
.
getCommand
());
// Set xjc work directory with the input java file
pb
.
directory
(
testWorkDir
.
toFile
());
pb
.
inheritIO
();
Process
p
=
pb
.
start
();
p
.
waitFor
();
p
.
destroy
();
}
// Compile java classes with javac tool
void
compileXjcGeneratedClasses
()
throws
Exception
{
JDKToolLauncher
javacLauncher
=
JDKToolLauncher
.
createUsingTestJDK
(
"javac"
);
javacLauncher
.
addToolArg
(
xjcResultDir
.
resolve
(
"ObjectFactory.java"
).
toString
());
javacLauncher
.
addToolArg
(
xjcResultDir
.
resolve
(
"TypesLongList.java"
).
toString
());
javacLauncher
.
addToolArg
(
xjcResultDir
.
resolve
(
"package-info.java"
).
toString
());
System
.
out
.
println
(
"Compiling xjc generated classes: "
+
Arrays
.
asList
(
javacLauncher
.
getCommand
()));
ProcessBuilder
pb
=
new
ProcessBuilder
(
javacLauncher
.
getCommand
());
pb
.
inheritIO
();
pb
.
directory
(
testWorkDir
.
toFile
());
Process
p
=
pb
.
start
();
p
.
waitFor
();
p
.
destroy
();
}
// Test schema filename
static
final
String
XSD_FILENAME
=
"testSchema.xsd"
;
// Package of java classes generated by xjc
static
final
String
TEST_PACKAGE
=
"testns_package"
;
// Name of generated java class
static
final
String
TEST_CLASS
=
TEST_PACKAGE
+
".TypesLongList"
;
// Method to get the list from xjc generated class
static
final
String
GET_LIST_METHOD
=
"getIn"
;
// Test working directory
Path
testWorkDir
;
// Test working directory URL
URL
testWorkDirUrl
;
// Directory with test src
Path
testSrcDir
;
// Directory with java files generated by xjc
Path
xjcResultDir
;
}
test/javax/xml/bind/xjc/8145039/testSchema.xsd
0 → 100644
浏览文件 @
beda5993
<xsd:schema
xmlns:xsd=
"http://www.w3.org/2001/XMLSchema"
xmlns:tns=
"http://testns_package"
xmlns:jaxb=
"http://java.sun.com/xml/ns/jaxb"
jaxb:version=
"2.0"
targetNamespace=
"http://testns_package"
>
<!-- Simple type list -->
<xsd:simpleType
name=
"LongList"
>
<xsd:list>
<xsd:simpleType>
<xsd:restriction
base=
"xsd:unsignedInt"
/>
</xsd:simpleType>
</xsd:list>
</xsd:simpleType>
<!--- Complex test type -->
<xsd:element
name=
"typesLongList"
>
<xsd:complexType>
<xsd:sequence>
<xsd:element
name=
"in"
type=
"tns:LongList"
/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录