Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e3d87e52
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看板
提交
e3d87e52
编写于
9月 14, 2010
作者:
O
okutsu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6984418: (cal) GregorianCalendar.setWeekDate doesn't check parameter consistency in non-lenient
Reviewed-by: peytoia
上级
8e6232b7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
30 deletion
+87
-30
src/share/classes/java/util/GregorianCalendar.java
src/share/classes/java/util/GregorianCalendar.java
+8
-6
test/java/util/Calendar/WeekDateTest.java
test/java/util/Calendar/WeekDateTest.java
+79
-24
未找到文件。
src/share/classes/java/util/GregorianCalendar.java
浏览文件 @
e3d87e52
...
@@ -2160,20 +2160,22 @@ public class GregorianCalendar extends Calendar {
...
@@ -2160,20 +2160,22 @@ public class GregorianCalendar extends Calendar {
gc
.
complete
();
gc
.
complete
();
}
}
if
(!
isLenient
()
&&
(
gc
.
getWeekYear
()
!=
weekYear
||
gc
.
internalGet
(
WEEK_OF_YEAR
)
!=
weekOfYear
||
gc
.
internalGet
(
DAY_OF_WEEK
)
!=
dayOfWeek
))
{
throw
new
IllegalArgumentException
();
}
set
(
ERA
,
gc
.
internalGet
(
ERA
));
set
(
ERA
,
gc
.
internalGet
(
ERA
));
set
(
YEAR
,
gc
.
internalGet
(
YEAR
));
set
(
YEAR
,
gc
.
internalGet
(
YEAR
));
set
(
MONTH
,
gc
.
internalGet
(
MONTH
));
set
(
MONTH
,
gc
.
internalGet
(
MONTH
));
set
(
DAY_OF_MONTH
,
gc
.
internalGet
(
DAY_OF_MONTH
));
set
(
DAY_OF_MONTH
,
gc
.
internalGet
(
DAY_OF_MONTH
));
// to avoid throwing an IllegalArgumentException in
// to avoid throwing an IllegalArgumentException in
// non-lenient, set WEEK_OF_YEAR
and DAY_OF_WEEK
internally
// non-lenient, set WEEK_OF_YEAR internally
internalSet
(
WEEK_OF_YEAR
,
weekOfYear
);
internalSet
(
WEEK_OF_YEAR
,
weekOfYear
);
internalSet
(
DAY_OF_WEEK
,
dayOfWeek
);
complete
();
complete
();
assert
getWeekYear
()
==
weekYear
;
assert
get
(
WEEK_OF_YEAR
)
==
weekOfYear
;
assert
get
(
DAY_OF_WEEK
)
==
dayOfWeek
;
}
}
/**
/**
...
...
test/java/util/Calendar/WeekDateTest.java
浏览文件 @
e3d87e52
...
@@ -36,27 +36,44 @@ public class WeekDateTest {
...
@@ -36,27 +36,44 @@ public class WeekDateTest {
// Week dates are in the ISO numbering for day-of-week.
// Week dates are in the ISO numbering for day-of-week.
static
int
[][][]
data
=
{
static
int
[][][]
data
=
{
// Calendar year-date, Week year-date
// Calendar year-date, Week year-date
{{
2005
,
01
,
01
},
{
2004
,
53
,
6
}},
{{
2005
,
01
,
01
},
{
2004
,
53
,
6
}},
{{
2005
,
01
,
02
},
{
2004
,
53
,
7
}},
{{
2005
,
01
,
02
},
{
2004
,
53
,
7
}},
{{
2005
,
12
,
31
},
{
2005
,
52
,
6
}},
{{
2005
,
12
,
31
},
{
2005
,
52
,
6
}},
{{
2007
,
01
,
01
},
{
2007
,
01
,
1
}},
{{
2007
,
01
,
01
},
{
2007
,
01
,
1
}},
{{
2007
,
12
,
30
},
{
2007
,
52
,
7
}},
{{
2007
,
12
,
30
},
{
2007
,
52
,
7
}},
{{
2007
,
12
,
31
},
{
2008
,
01
,
1
}},
{{
2007
,
12
,
31
},
{
2008
,
01
,
1
}},
{{
2008
,
01
,
01
},
{
2008
,
01
,
2
}},
{{
2008
,
01
,
01
},
{
2008
,
01
,
2
}},
{{
2008
,
12
,
29
},
{
2009
,
01
,
1
}},
{{
2008
,
12
,
29
},
{
2009
,
01
,
1
}},
{{
2008
,
12
,
31
},
{
2009
,
01
,
3
}},
{{
2008
,
12
,
31
},
{
2009
,
01
,
3
}},
{{
2009
,
01
,
01
},
{
2009
,
01
,
4
}},
{{
2009
,
01
,
01
},
{
2009
,
01
,
4
}},
{{
2009
,
12
,
31
},
{
2009
,
53
,
4
}},
{{
2009
,
12
,
31
},
{
2009
,
53
,
4
}},
{{
2010
,
01
,
03
},
{
2009
,
53
,
7
}},
{{
2010
,
01
,
03
},
{
2009
,
53
,
7
}},
{{
2009
,
12
,
31
},
{
2009
,
53
,
4
}},
{{
2009
,
12
,
31
},
{
2009
,
53
,
4
}},
{{
2010
,
01
,
01
},
{
2009
,
53
,
5
}},
{{
2010
,
01
,
01
},
{
2009
,
53
,
5
}},
{{
2010
,
01
,
02
},
{
2009
,
53
,
6
}},
{{
2010
,
01
,
02
},
{
2009
,
53
,
6
}},
{{
2010
,
01
,
03
},
{
2009
,
53
,
7
}},
{{
2010
,
01
,
03
},
{
2009
,
53
,
7
}},
{{
2008
,
12
,
28
},
{
2008
,
52
,
7
}},
{{
2008
,
12
,
28
},
{
2008
,
52
,
7
}},
{{
2008
,
12
,
29
},
{
2009
,
01
,
1
}},
{{
2008
,
12
,
29
},
{
2009
,
01
,
1
}},
{{
2008
,
12
,
30
},
{
2009
,
01
,
2
}},
{{
2008
,
12
,
30
},
{
2009
,
01
,
2
}},
{{
2008
,
12
,
31
},
{
2009
,
01
,
3
}},
{{
2008
,
12
,
31
},
{
2009
,
01
,
3
}},
{{
2009
,
01
,
01
},
{
2009
,
01
,
4
}}
{{
2009
,
01
,
01
},
{
2009
,
01
,
4
}}
};
// Data for leniency test
static
final
int
[][][]
leniencyData
=
{
{{
2008
,
12
,
28
},
{
2009
,
0
,
7
}},
{{
2008
,
12
,
21
},
{
2009
,
-
1
,
7
}},
{{
2009
,
1
,
4
},
{
2008
,
53
,
7
}},
};
static
final
int
[][]
invalidData
=
{
{
2010
,
-
1
,
1
},
{
2010
,
00
,
1
},
{
2010
,
55
,
1
},
{
2010
,
03
,
0
},
{
2010
,
04
,
8
},
{
2010
,
04
,
19
},
{
2010
,
05
,
-
1
},
};
};
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
@@ -65,7 +82,7 @@ public class WeekDateTest {
...
@@ -65,7 +82,7 @@ public class WeekDateTest {
int
[]
expected
=
dates
[
0
];
int
[]
expected
=
dates
[
0
];
int
[]
weekDate
=
dates
[
1
];
int
[]
weekDate
=
dates
[
1
];
// Convert ISO 8601 day-of-week to Calendar.DAY_OF_WEEK.
// Convert ISO 8601 day-of-week to Calendar.DAY_OF_WEEK.
int
dayOfWeek
=
weekDate
[
2
]
==
7
?
SUNDAY
:
weekDate
[
2
]
+
1
;
int
dayOfWeek
=
getCalendarDayOfWeek
(
weekDate
[
2
])
;
cal
.
clear
();
cal
.
clear
();
cal
.
setWeekDate
(
weekDate
[
0
],
weekDate
[
1
],
dayOfWeek
);
cal
.
setWeekDate
(
weekDate
[
0
],
weekDate
[
1
],
dayOfWeek
);
...
@@ -102,21 +119,55 @@ public class WeekDateTest {
...
@@ -102,21 +119,55 @@ public class WeekDateTest {
n
,
cal
.
getActualMaximum
(
WEEK_OF_YEAR
));
n
,
cal
.
getActualMaximum
(
WEEK_OF_YEAR
));
throw
new
RuntimeException
(
s
);
throw
new
RuntimeException
(
s
);
}
}
cal
.
setWeekDate
(
cal
.
getWeekYear
(),
1
,
MONDAY
);
cal
.
setWeekDate
(
cal
.
getWeekYear
(),
1
,
MONDAY
);
System
.
out
.
println
(
cal
.
getTime
());
if
(
cal
.
getWeeksInWeekYear
()
!=
n
)
{
if
(
cal
.
getWeeksInWeekYear
()
!=
n
)
{
String
s
=
String
.
format
(
"first day: got %d, expected %d%n"
,
String
s
=
String
.
format
(
"first day: got %d, expected %d%n"
,
cal
.
getWeeksInWeekYear
(),
n
);
cal
.
getWeeksInWeekYear
(),
n
);
throw
new
RuntimeException
(
s
);
throw
new
RuntimeException
(
s
);
}
}
cal
.
setWeekDate
(
cal
.
getWeekYear
(),
n
,
SUNDAY
);
cal
.
setWeekDate
(
cal
.
getWeekYear
(),
n
,
SUNDAY
);
System
.
out
.
println
(
cal
.
getTime
());
if
(
cal
.
getWeeksInWeekYear
()
!=
n
)
{
if
(
cal
.
getWeeksInWeekYear
()
!=
n
)
{
String
s
=
String
.
format
(
"last day: got %d, expected %d%n"
,
String
s
=
String
.
format
(
"last day: got %d, expected %d%n"
,
cal
.
getWeeksInWeekYear
(),
n
);
cal
.
getWeeksInWeekYear
(),
n
);
throw
new
RuntimeException
(
s
);
throw
new
RuntimeException
(
s
);
}
}
}
}
// Test lenient mode with out of range values.
for
(
int
[][]
dates
:
leniencyData
)
{
int
[]
expected
=
dates
[
0
];
int
[]
weekDate
=
dates
[
1
];
// Convert ISO 8601 day-of-week to Calendar.DAY_OF_WEEK.
int
dayOfWeek
=
getCalendarDayOfWeek
(
weekDate
[
2
]);
cal
.
clear
();
cal
.
setWeekDate
(
weekDate
[
0
],
weekDate
[
1
],
dayOfWeek
);
if
(
cal
.
get
(
YEAR
)
!=
expected
[
0
]
||
cal
.
get
(
MONTH
)+
1
!=
expected
[
1
]
||
cal
.
get
(
DAY_OF_MONTH
)
!=
expected
[
2
])
{
String
s
=
String
.
format
(
"got=%4d-%02d-%02d, expected=%4d-%02d-%02d"
,
cal
.
get
(
YEAR
),
cal
.
get
(
MONTH
)+
1
,
cal
.
get
(
DAY_OF_MONTH
),
expected
[
0
],
expected
[
1
],
expected
[
2
]);
throw
new
RuntimeException
(
s
);
}
}
// Test non-lenient mode
cal
.
setLenient
(
false
);
for
(
int
[]
date
:
invalidData
)
{
cal
.
clear
();
try
{
// Use the raw dayOfWeek value as invalid data
cal
.
setWeekDate
(
date
[
0
],
date
[
1
],
date
[
2
]);
String
s
=
String
.
format
(
"didn't throw an IllegalArgumentException with"
+
" %d, %d, %d"
,
date
[
0
],
date
[
1
],
date
[
2
]);
throw
new
RuntimeException
(
s
);
}
catch
(
IllegalArgumentException
e
)
{
// OK
}
}
}
}
private
static
GregorianCalendar
newCalendar
()
{
private
static
GregorianCalendar
newCalendar
()
{
...
@@ -130,4 +181,8 @@ public class WeekDateTest {
...
@@ -130,4 +181,8 @@ public class WeekDateTest {
cal
.
setMinimalDaysInFirstWeek
(
4
);
cal
.
setMinimalDaysInFirstWeek
(
4
);
return
cal
;
return
cal
;
}
}
private
static
int
getCalendarDayOfWeek
(
int
isoDayOfWeek
)
{
return
(
isoDayOfWeek
==
7
)
?
SUNDAY
:
isoDayOfWeek
+
1
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录