Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
4fb55539
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4fb55539
编写于
12月 08, 2010
作者:
O
okutsu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6653944: (cal) BuddhistCalendar yearOffset erased when deserialized
Reviewed-by: peytoia
上级
0477bd12
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
103 addition
and
4 deletion
+103
-4
src/share/classes/sun/util/BuddhistCalendar.java
src/share/classes/sun/util/BuddhistCalendar.java
+17
-4
test/sun/util/calendar/Bug6653944.java
test/sun/util/calendar/Bug6653944.java
+86
-0
未找到文件。
src/share/classes/sun/util/BuddhistCalendar.java
浏览文件 @
4fb55539
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
package
sun.util
;
package
sun.util
;
import
java.io.IOException
;
import
java.io.ObjectInputStream
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.GregorianCalendar
;
import
java.util.GregorianCalendar
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -42,7 +44,7 @@ public class BuddhistCalendar extends GregorianCalendar {
...
@@ -42,7 +44,7 @@ public class BuddhistCalendar extends GregorianCalendar {
private
static
final
long
serialVersionUID
=
-
8527488697350388578L
;
private
static
final
long
serialVersionUID
=
-
8527488697350388578L
;
private
static
final
int
buddhistOffset
=
543
;
private
static
final
int
BUDDHIST_YEAR_OFFSET
=
543
;
///////////////
///////////////
// Constructors
// Constructors
...
@@ -103,7 +105,7 @@ public class BuddhistCalendar extends GregorianCalendar {
...
@@ -103,7 +105,7 @@ public class BuddhistCalendar extends GregorianCalendar {
* Generates the hash code for the BuddhistCalendar object
* Generates the hash code for the BuddhistCalendar object
*/
*/
public
int
hashCode
()
{
public
int
hashCode
()
{
return
super
.
hashCode
()
^
buddhistOffset
;
return
super
.
hashCode
()
^
BUDDHIST_YEAR_OFFSET
;
}
}
/**
/**
...
@@ -141,6 +143,8 @@ public class BuddhistCalendar extends GregorianCalendar {
...
@@ -141,6 +143,8 @@ public class BuddhistCalendar extends GregorianCalendar {
public
void
add
(
int
field
,
int
amount
)
public
void
add
(
int
field
,
int
amount
)
{
{
int
savedYearOffset
=
yearOffset
;
int
savedYearOffset
=
yearOffset
;
// To let the superclass calculate date-time values correctly,
// temporarily make this GregorianCalendar.
yearOffset
=
0
;
yearOffset
=
0
;
try
{
try
{
super
.
add
(
field
,
amount
);
super
.
add
(
field
,
amount
);
...
@@ -159,6 +163,8 @@ public class BuddhistCalendar extends GregorianCalendar {
...
@@ -159,6 +163,8 @@ public class BuddhistCalendar extends GregorianCalendar {
public
void
roll
(
int
field
,
int
amount
)
public
void
roll
(
int
field
,
int
amount
)
{
{
int
savedYearOffset
=
yearOffset
;
int
savedYearOffset
=
yearOffset
;
// To let the superclass calculate date-time values correctly,
// temporarily make this GregorianCalendar.
yearOffset
=
0
;
yearOffset
=
0
;
try
{
try
{
super
.
roll
(
field
,
amount
);
super
.
roll
(
field
,
amount
);
...
@@ -246,6 +252,8 @@ public class BuddhistCalendar extends GregorianCalendar {
...
@@ -246,6 +252,8 @@ public class BuddhistCalendar extends GregorianCalendar {
*/
*/
public
int
getActualMaximum
(
int
field
)
{
public
int
getActualMaximum
(
int
field
)
{
int
savedYearOffset
=
yearOffset
;
int
savedYearOffset
=
yearOffset
;
// To let the superclass calculate date-time values correctly,
// temporarily make this GregorianCalendar.
yearOffset
=
0
;
yearOffset
=
0
;
try
{
try
{
return
super
.
getActualMaximum
(
field
);
return
super
.
getActualMaximum
(
field
);
...
@@ -275,11 +283,16 @@ public class BuddhistCalendar extends GregorianCalendar {
...
@@ -275,11 +283,16 @@ public class BuddhistCalendar extends GregorianCalendar {
// Skip the year number
// Skip the year number
while
(
Character
.
isDigit
(
s
.
charAt
(
p
++)))
while
(
Character
.
isDigit
(
s
.
charAt
(
p
++)))
;
;
int
year
=
internalGet
(
YEAR
)
+
buddhistOffset
;
int
year
=
internalGet
(
YEAR
)
+
BUDDHIST_YEAR_OFFSET
;
sb
.
append
(
year
).
append
(
s
.
substring
(
p
-
1
));
sb
.
append
(
year
).
append
(
s
.
substring
(
p
-
1
));
return
sb
.
toString
();
return
sb
.
toString
();
}
}
private
transient
int
yearOffset
=
buddhistOffset
;
private
transient
int
yearOffset
=
BUDDHIST_YEAR_OFFSET
;
private
void
readObject
(
ObjectInputStream
stream
)
throws
IOException
,
ClassNotFoundException
{
stream
.
defaultReadObject
();
yearOffset
=
BUDDHIST_YEAR_OFFSET
;
}
}
}
test/sun/util/calendar/Bug6653944.java
0 → 100644
浏览文件 @
4fb55539
/*
* 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 6653944
*@summary Deserialization tests for YEAR calculcations
*/
import
java.io.*
;
import
java.util.*
;
public
class
Bug6653944
{
private
static
int
errorCount
=
0
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Calendar
buddhist
=
Calendar
.
getInstance
(
new
Locale
(
"th"
,
"TH"
));
int
expectedYear
=
buddhist
.
get
(
Calendar
.
YEAR
);
Calendar
deserialized
=
(
Calendar
)
deserialize
(
serialize
(
buddhist
));
compare
(
deserialized
,
buddhist
);
int
deserializedYear
=
deserialized
.
get
(
Calendar
.
YEAR
);
compare
(
deserializedYear
,
expectedYear
);
// test add(YEAR, n).
buddhist
.
add
(
Calendar
.
YEAR
,
12
);
expectedYear
=
buddhist
.
get
(
Calendar
.
YEAR
);
deserialized
.
add
(
Calendar
.
YEAR
,
12
);
deserializedYear
=
deserialized
.
get
(
Calendar
.
YEAR
);
compare
(
deserialized
,
buddhist
);
compare
(
deserializedYear
,
expectedYear
);
if
(
errorCount
>
0
)
{
throw
new
RuntimeException
(
"Bug6653944: failed"
);
}
}
private
static
void
compare
(
int
got
,
int
expected
)
{
if
(
got
!=
expected
)
{
System
.
err
.
println
(
"got "
+
got
+
", expected "
+
expected
);
errorCount
++;
}
}
private
static
void
compare
(
Calendar
got
,
Calendar
expected
)
{
if
(!
got
.
equals
(
expected
))
{
System
.
err
.
println
(
"got "
+
got
+
", expected "
+
expected
);
errorCount
++;
}
}
private
static
byte
[]
serialize
(
Serializable
obj
)
throws
Exception
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
ObjectOutputStream
oos
=
new
ObjectOutputStream
(
baos
);
oos
.
writeObject
(
obj
);
oos
.
close
();
return
baos
.
toByteArray
();
}
private
static
Object
deserialize
(
byte
[]
data
)
throws
Exception
{
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
data
);
ObjectInputStream
ois
=
new
ObjectInputStream
(
bais
);
return
ois
.
readObject
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录