Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
76d193f3
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看板
提交
76d193f3
编写于
8月 23, 2016
作者:
I
igerasim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8164366: ZoneOffset.ofHoursMinutesSeconds() does not reject invalid input
Reviewed-by: scolebourne, ntv, coffeys
上级
6d693369
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
11 deletion
+32
-11
src/share/classes/java/time/ZoneOffset.java
src/share/classes/java/time/ZoneOffset.java
+11
-10
test/java/time/tck/java/time/TCKZoneOffset.java
test/java/time/tck/java/time/TCKZoneOffset.java
+21
-1
未找到文件。
src/share/classes/java/time/ZoneOffset.java
浏览文件 @
76d193f3
/*
* Copyright (c) 2012, 201
5
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 201
6
, 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
...
...
@@ -375,15 +375,15 @@ public final class ZoneOffset
}
else
if
((
minutes
>
0
&&
seconds
<
0
)
||
(
minutes
<
0
&&
seconds
>
0
))
{
throw
new
DateTimeException
(
"Zone offset minutes and seconds must have the same sign"
);
}
if
(
Math
.
abs
(
minutes
)
>
59
)
{
throw
new
DateTimeException
(
"Zone offset minutes not in valid range:
abs(value)
"
+
Math
.
abs
(
minutes
)
+
" is not in the range 0
to 59"
);
if
(
minutes
<
-
59
||
minutes
>
59
)
{
throw
new
DateTimeException
(
"Zone offset minutes not in valid range:
value
"
+
minutes
+
" is not in the range -59
to 59"
);
}
if
(
Math
.
abs
(
seconds
)
>
59
)
{
throw
new
DateTimeException
(
"Zone offset seconds not in valid range:
abs(value)
"
+
Math
.
abs
(
seconds
)
+
" is not in the range 0
to 59"
);
if
(
seconds
<
-
59
||
seconds
>
59
)
{
throw
new
DateTimeException
(
"Zone offset seconds not in valid range:
value
"
+
seconds
+
" is not in the range -59
to 59"
);
}
if
(
Math
.
abs
(
hours
)
==
18
&&
(
Math
.
abs
(
minutes
)
>
0
||
Math
.
abs
(
seconds
)
>
0
)
)
{
if
(
Math
.
abs
(
hours
)
==
18
&&
(
minutes
|
seconds
)
!=
0
)
{
throw
new
DateTimeException
(
"Zone offset not in valid range: -18:00 to +18:00"
);
}
}
...
...
@@ -411,7 +411,7 @@ public final class ZoneOffset
* @throws DateTimeException if the offset is not in the required range
*/
public
static
ZoneOffset
ofTotalSeconds
(
int
totalSeconds
)
{
if
(
Math
.
abs
(
totalSeconds
)
>
MAX_SECONDS
)
{
if
(
totalSeconds
<
-
MAX_SECONDS
||
totalSeconds
>
MAX_SECONDS
)
{
throw
new
DateTimeException
(
"Zone offset not in valid range: -18:00 to +18:00"
);
}
if
(
totalSeconds
%
(
15
*
SECONDS_PER_MINUTE
)
==
0
)
{
...
...
@@ -696,11 +696,12 @@ public final class ZoneOffset
* The comparison is "consistent with equals", as defined by {@link Comparable}.
*
* @param other the other date to compare to, not null
* @return the comparator value, negative if less, postive if greater
* @return the comparator value, negative if less, pos
i
tive if greater
* @throws NullPointerException if {@code other} is null
*/
@Override
public
int
compareTo
(
ZoneOffset
other
)
{
// abs(totalSeconds) <= MAX_SECONDS, so no overflow can happen here
return
other
.
totalSeconds
-
totalSeconds
;
}
...
...
test/java/time/tck/java/time/TCKZoneOffset.java
浏览文件 @
76d193f3
/*
* Copyright (c) 2012, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 201
6
, 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
...
...
@@ -419,6 +419,21 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
ZoneOffset
.
ofHoursMinutesSeconds
(-
19
,
0
,
0
);
}
@Test
(
expectedExceptions
=
DateTimeException
.
class
)
public
void
test_factory_int_hours_minutes_seconds_minutesMinValue
()
{
ZoneOffset
.
ofHoursMinutesSeconds
(
0
,
Integer
.
MIN_VALUE
,
-
1
);
}
@Test
(
expectedExceptions
=
DateTimeException
.
class
)
public
void
test_factory_int_hours_minutes_seconds_secondsMinValue
()
{
ZoneOffset
.
ofHoursMinutesSeconds
(
0
,
0
,
Integer
.
MIN_VALUE
);
}
@Test
(
expectedExceptions
=
DateTimeException
.
class
)
public
void
test_factory_int_hours_minutes_seconds_minutesAndSecondsMinValue
()
{
ZoneOffset
.
ofHoursMinutesSeconds
(
0
,
Integer
.
MIN_VALUE
,
Integer
.
MIN_VALUE
);
}
//-----------------------------------------------------------------------
@Test
public
void
test_factory_ofTotalSeconds
()
{
...
...
@@ -437,6 +452,11 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
ZoneOffset
.
ofTotalSeconds
(-
18
*
60
*
60
-
1
);
}
@Test
(
expectedExceptions
=
DateTimeException
.
class
)
public
void
test_factory_ofTotalSeconds_minValue
()
{
ZoneOffset
.
ofTotalSeconds
(
Integer
.
MIN_VALUE
);
}
//-----------------------------------------------------------------------
// from()
//-----------------------------------------------------------------------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录