Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
5e449602
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看板
提交
5e449602
编写于
4月 15, 2016
作者:
R
rpatil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8151431: DateFormatSymbols triggers this.clone() in the constructor
Reviewed-by: naoto, peytoia
上级
6fd86567
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
130 addition
and
47 deletion
+130
-47
src/share/classes/java/text/DateFormatSymbols.java
src/share/classes/java/text/DateFormatSymbols.java
+80
-47
test/java/text/Format/DateFormat/DateFormatSymbolsCloneTest.java
...va/text/Format/DateFormat/DateFormatSymbolsCloneTest.java
+50
-0
未找到文件。
src/share/classes/java/text/DateFormatSymbols.java
浏览文件 @
5e449602
/*
* Copyright (c) 1996, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
...
...
@@ -47,7 +47,6 @@ import java.util.Arrays;
import
java.util.Locale
;
import
java.util.Objects
;
import
java.util.ResourceBundle
;
import
java.util.TimeZone
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
sun.util.locale.provider.LocaleProviderAdapter
;
...
...
@@ -146,6 +145,12 @@ public class DateFormatSymbols implements Serializable, Cloneable {
initializeData
(
locale
);
}
/**
* Constructs an uninitialized DateFormatSymbols.
*/
private
DateFormatSymbols
(
boolean
flag
)
{
}
/**
* Era strings. For example: "AD" and "BC". An array of 2 strings,
* indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>.
...
...
@@ -677,54 +682,80 @@ public class DateFormatSymbols implements Serializable, Cloneable {
*/
transient
volatile
int
cachedHashCode
=
0
;
private
void
initializeData
(
Locale
desiredLocale
)
{
locale
=
desiredLocale
;
// Copy values of a cached instance if any.
/**
* Initializes this DateFormatSymbols with the locale data. This method uses
* a cached DateFormatSymbols instance for the given locale if available. If
* there's no cached one, this method creates an uninitialized instance and
* populates its fields from the resource bundle for the locale, and caches
* the instance. Note: zoneStrings isn't initialized in this method.
*/
private
void
initializeData
(
Locale
locale
)
{
SoftReference
<
DateFormatSymbols
>
ref
=
cachedInstances
.
get
(
locale
);
DateFormatSymbols
dfs
;
if
(
ref
!=
null
&&
(
dfs
=
ref
.
get
())
!=
null
)
{
copyMembers
(
dfs
,
this
);
return
;
}
// Initialize the fields from the ResourceBundle for locale.
LocaleProviderAdapter
adapter
=
LocaleProviderAdapter
.
getAdapter
(
DateFormatSymbolsProvider
.
class
,
locale
);
// Avoid any potential recursions
if
(!(
adapter
instanceof
ResourceBundleBasedAdapter
))
{
adapter
=
LocaleProviderAdapter
.
getResourceBundleBased
();
}
ResourceBundle
resource
=
((
ResourceBundleBasedAdapter
)
adapter
).
getLocaleData
().
getDateFormatData
(
locale
);
// JRE and CLDR use different keys
// JRE: Eras, short.Eras and narrow.Eras
// CLDR: long.Eras, Eras and narrow.Eras
if
(
resource
.
containsKey
(
"Eras"
))
{
eras
=
resource
.
getStringArray
(
"Eras"
);
}
else
if
(
resource
.
containsKey
(
"long.Eras"
))
{
eras
=
resource
.
getStringArray
(
"long.Eras"
);
}
else
if
(
resource
.
containsKey
(
"short.Eras"
))
{
eras
=
resource
.
getStringArray
(
"short.Eras"
);
}
months
=
resource
.
getStringArray
(
"MonthNames"
);
shortMonths
=
resource
.
getStringArray
(
"MonthAbbreviations"
);
ampms
=
resource
.
getStringArray
(
"AmPmMarkers"
);
localPatternChars
=
resource
.
getString
(
"DateTimePatternChars"
);
// Day of week names are stored in a 1-based array.
weekdays
=
toOneBasedArray
(
resource
.
getStringArray
(
"DayNames"
));
shortWeekdays
=
toOneBasedArray
(
resource
.
getStringArray
(
"DayAbbreviations"
));
// Put a clone in the cache
ref
=
new
SoftReference
<>((
DateFormatSymbols
)
this
.
clone
());
SoftReference
<
DateFormatSymbols
>
x
=
cachedInstances
.
putIfAbsent
(
locale
,
ref
);
if
(
x
!=
null
)
{
DateFormatSymbols
y
=
x
.
get
();
if
(
y
==
null
)
{
// Replace the empty SoftReference with ref.
cachedInstances
.
put
(
locale
,
ref
);
if
(
ref
==
null
||
(
dfs
=
ref
.
get
())
==
null
)
{
if
(
ref
!=
null
)
{
// Remove the empty SoftReference
cachedInstances
.
remove
(
locale
,
ref
);
}
dfs
=
new
DateFormatSymbols
(
false
);
// Initialize the fields from the ResourceBundle for locale.
LocaleProviderAdapter
adapter
=
LocaleProviderAdapter
.
getAdapter
(
DateFormatSymbolsProvider
.
class
,
locale
);
// Avoid any potential recursions
if
(!(
adapter
instanceof
ResourceBundleBasedAdapter
))
{
adapter
=
LocaleProviderAdapter
.
getResourceBundleBased
();
}
ResourceBundle
resource
=
((
ResourceBundleBasedAdapter
)
adapter
).
getLocaleData
().
getDateFormatData
(
locale
);
dfs
.
locale
=
locale
;
// JRE and CLDR use different keys
// JRE: Eras, short.Eras and narrow.Eras
// CLDR: long.Eras, Eras and narrow.Eras
if
(
resource
.
containsKey
(
"Eras"
))
{
dfs
.
eras
=
resource
.
getStringArray
(
"Eras"
);
}
else
if
(
resource
.
containsKey
(
"long.Eras"
))
{
dfs
.
eras
=
resource
.
getStringArray
(
"long.Eras"
);
}
else
if
(
resource
.
containsKey
(
"short.Eras"
))
{
dfs
.
eras
=
resource
.
getStringArray
(
"short.Eras"
);
}
dfs
.
months
=
resource
.
getStringArray
(
"MonthNames"
);
dfs
.
shortMonths
=
resource
.
getStringArray
(
"MonthAbbreviations"
);
dfs
.
ampms
=
resource
.
getStringArray
(
"AmPmMarkers"
);
dfs
.
localPatternChars
=
resource
.
getString
(
"DateTimePatternChars"
);
// Day of week names are stored in a 1-based array.
dfs
.
weekdays
=
toOneBasedArray
(
resource
.
getStringArray
(
"DayNames"
));
dfs
.
shortWeekdays
=
toOneBasedArray
(
resource
.
getStringArray
(
"DayAbbreviations"
));
// Put dfs in the cache
ref
=
new
SoftReference
<>(
dfs
);
SoftReference
<
DateFormatSymbols
>
x
=
cachedInstances
.
putIfAbsent
(
locale
,
ref
);
if
(
x
!=
null
)
{
DateFormatSymbols
y
=
x
.
get
();
if
(
y
==
null
)
{
// Replace the empty SoftReference with ref.
cachedInstances
.
replace
(
locale
,
x
,
ref
);
}
else
{
ref
=
x
;
dfs
=
y
;
}
}
// If the bundle's locale isn't the target locale, put another cache
// entry for the bundle's locale.
Locale
bundleLocale
=
resource
.
getLocale
();
if
(!
bundleLocale
.
equals
(
locale
))
{
SoftReference
<
DateFormatSymbols
>
z
=
cachedInstances
.
putIfAbsent
(
bundleLocale
,
ref
);
if
(
z
!=
null
&&
z
.
get
()
==
null
)
{
cachedInstances
.
replace
(
bundleLocale
,
z
,
ref
);
}
}
}
// Copy the field values from dfs to this instance.
copyMembers
(
dfs
,
this
);
}
private
static
String
[]
toOneBasedArray
(
String
[]
src
)
{
...
...
@@ -806,12 +837,14 @@ public class DateFormatSymbols implements Serializable, Cloneable {
/**
* Clones all the data members from the source DateFormatSymbols to
* the target DateFormatSymbols. This is only for subclasses.
* the target DateFormatSymbols.
*
* @param src the source DateFormatSymbols.
* @param dst the target DateFormatSymbols.
*/
private
void
copyMembers
(
DateFormatSymbols
src
,
DateFormatSymbols
dst
)
{
dst
.
locale
=
src
.
locale
;
dst
.
eras
=
Arrays
.
copyOf
(
src
.
eras
,
src
.
eras
.
length
);
dst
.
months
=
Arrays
.
copyOf
(
src
.
months
,
src
.
months
.
length
);
dst
.
shortMonths
=
Arrays
.
copyOf
(
src
.
shortMonths
,
src
.
shortMonths
.
length
);
...
...
test/java/text/Format/DateFormat/DateFormatSymbolsCloneTest.java
0 → 100644
浏览文件 @
5e449602
/*
* 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 8151431
* @summary Make sure that clone() of a DateFormatSymbols subclass is not
* called from DateFormatSymbols constructor.
*/
import
java.text.DateFormatSymbols
;
public
class
DateFormatSymbolsCloneTest
extends
DateFormatSymbols
{
private
int
value
;
public
DateFormatSymbolsCloneTest
()
{
value
=
1
;
}
@Override
public
Object
clone
()
{
if
(
this
.
value
==
0
)
{
throw
new
RuntimeException
(
"clone() should not be called from a DateFormatSymbols constructor"
);
}
return
super
.
clone
();
}
public
static
void
main
(
String
[]
args
)
{
new
DateFormatSymbolsCloneTest
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录