Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
d082dd79
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看板
提交
d082dd79
编写于
4月 18, 2013
作者:
J
jgish
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8012005: LogManager needs test to ensure stack trace is not being done to find bundle
Reviewed-by: mchung
上级
f0c72104
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
480 addition
and
0 deletion
+480
-0
test/java/util/logging/bundlesearch/ClassPathTestBundle_en.properties
...il/logging/bundlesearch/ClassPathTestBundle_en.properties
+25
-0
test/java/util/logging/bundlesearch/IndirectlyLoadABundle.java
...java/util/logging/bundlesearch/IndirectlyLoadABundle.java
+92
-0
test/java/util/logging/bundlesearch/LoadItUp.java
test/java/util/logging/bundlesearch/LoadItUp.java
+62
-0
test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java
...a/util/logging/bundlesearch/ResourceBundleSearchTest.java
+251
-0
test/java/util/logging/bundlesearch/resources/ContextClassLoaderTestBundle_en.properties
...arch/resources/ContextClassLoaderTestBundle_en.properties
+25
-0
test/java/util/logging/bundlesearch/resources/StackSearchableResource_en.properties
...dlesearch/resources/StackSearchableResource_en.properties
+25
-0
未找到文件。
test/java/util/logging/bundlesearch/ClassPathTestBundle_en.properties
0 → 100644
浏览文件 @
d082dd79
#
# Copyright (c) 2013, 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.
#
sample1
=
translation #2 for sample1
sample2
=
translation #2 for sample2
supports-test
=
ResourceBundleSearchTest
test/java/util/logging/bundlesearch/IndirectlyLoadABundle.java
0 → 100644
浏览文件 @
d082dd79
/*
* Copyright (c) 2013, 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.
*/
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.nio.file.Paths
;
/**
* This class is used to ensure that a resource bundle loadable by a classloader
* is on the caller's stack, but not on the classpath or TCCL to ensure that
* Logger.getLogger() can't load the bundle via a stack search
*
* @author Jim Gish
*/
public
class
IndirectlyLoadABundle
{
private
final
static
String
rbName
=
"StackSearchableResource"
;
public
boolean
loadAndTest
()
throws
Throwable
{
// Find out where we are running from so we can setup the URLClassLoader URLs
// test.src and test.classes will be set if running in jtreg, but probably
// not otherwise
String
testDir
=
System
.
getProperty
(
"test.src"
,
System
.
getProperty
(
"user.dir"
));
String
testClassesDir
=
System
.
getProperty
(
"test.classes"
,
System
.
getProperty
(
"user.dir"
));
String
sep
=
System
.
getProperty
(
"file.separator"
);
URL
[]
urls
=
new
URL
[
2
];
// Allow for both jtreg and standalone cases here
urls
[
0
]
=
Paths
.
get
(
testDir
,
"resources"
).
toUri
().
toURL
();
urls
[
1
]
=
Paths
.
get
(
testClassesDir
).
toUri
().
toURL
();
System
.
out
.
println
(
"INFO: urls[0] = "
+
urls
[
0
]);
System
.
out
.
println
(
"INFO: urls[1] = "
+
urls
[
1
]);
// Make sure we can find it via the URLClassLoader
URLClassLoader
yetAnotherResourceCL
=
new
URLClassLoader
(
urls
,
null
);
if
(!
testForValidResourceSetup
(
yetAnotherResourceCL
))
{
throw
new
Exception
(
"Couldn't directly load bundle "
+
rbName
+
" as expected. Test config problem"
);
}
// But it shouldn't be available via the system classloader
ClassLoader
myCL
=
this
.
getClass
().
getClassLoader
();
if
(
testForValidResourceSetup
(
myCL
))
{
throw
new
Exception
(
"Was able to directly load bundle "
+
rbName
+
" from "
+
myCL
+
" but shouldn't have been"
+
" able to. Test config problem"
);
}
Class
<?>
loadItUpClazz
=
Class
.
forName
(
"LoadItUp"
,
true
,
yetAnotherResourceCL
);
ClassLoader
actual
=
loadItUpClazz
.
getClassLoader
();
if
(
actual
!=
yetAnotherResourceCL
)
{
throw
new
Exception
(
"LoadItUp was loaded by an unexpected CL: "
+
actual
);
}
Object
loadItUp
=
loadItUpClazz
.
newInstance
();
Method
testMethod
=
loadItUpClazz
.
getMethod
(
"test"
,
String
.
class
);
try
{
return
(
Boolean
)
testMethod
.
invoke
(
loadItUp
,
rbName
);
}
catch
(
InvocationTargetException
ex
)
{
throw
ex
.
getTargetException
();
}
}
private
boolean
testForValidResourceSetup
(
ClassLoader
cl
)
{
// First make sure the test environment is setup properly and the bundle actually
// exists
return
ResourceBundleSearchTest
.
isOnClassPath
(
rbName
,
cl
);
}
}
test/java/util/logging/bundlesearch/LoadItUp.java
0 → 100644
浏览文件 @
d082dd79
/*
* Copyright (c) 2013, 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.
*/
import
java.util.MissingResourceException
;
import
java.util.logging.Logger
;
/*
* This class is loaded onto the call stack when the test method is called
* and then its classloader can be used to find a property bundle in the same
* directory as the class. However, Logger is not allowed
* to find the bundle by looking up the stack for this classloader.
* We verify that this cannot happen.
*
* @author Jim Gish
*/
public
class
LoadItUp
{
private
final
static
boolean
DEBUG
=
false
;
public
Boolean
test
(
String
rbName
)
throws
Exception
{
// we should not be able to find the resource in this directory via
// getLogger calls. The only way that would be possible given this setup
// is that if Logger.getLogger searched up the call stack
return
lookupBundle
(
rbName
);
}
private
boolean
lookupBundle
(
String
rbName
)
{
// See if Logger.getLogger can find the resource in this directory
try
{
Logger
aLogger
=
Logger
.
getLogger
(
"NestedLogger"
,
rbName
);
}
catch
(
MissingResourceException
re
)
{
if
(
DEBUG
)
{
System
.
out
.
println
(
"As expected, LoadItUp.lookupBundle() did not find the bundle "
+
rbName
);
}
return
false
;
}
System
.
out
.
println
(
"FAILED: LoadItUp.lookupBundle() found the bundle "
+
rbName
+
" using a stack search."
);
return
true
;
}
}
test/java/util/logging/bundlesearch/ResourceBundleSearchTest.java
0 → 100644
浏览文件 @
d082dd79
/*
* Copyright (c) 2013, 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 8002070
* @summary Remove the stack search for a resource bundle Logger to use
* @author Jim Gish
* @build ResourceBundleSearchTest IndirectlyLoadABundle LoadItUp
* @run main ResourceBundleSearchTest
*/
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.MissingResourceException
;
import
java.util.ResourceBundle
;
import
java.util.logging.Logger
;
public
class
ResourceBundleSearchTest
{
private
final
static
boolean
DEBUG
=
false
;
private
final
static
String
LOGGER_PREFIX
=
"myLogger."
;
private
static
int
loggerNum
=
0
;
private
final
static
String
PROP_RB_NAME
=
"ClassPathTestBundle"
;
private
final
static
String
TCCL_TEST_BUNDLE
=
"ContextClassLoaderTestBundle"
;
private
static
int
numPass
=
0
;
private
static
int
numFail
=
0
;
private
static
List
<
String
>
msgs
=
new
ArrayList
<>();
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
ResourceBundleSearchTest
test
=
new
ResourceBundleSearchTest
();
test
.
runTests
();
}
private
void
runTests
()
throws
Throwable
{
// ensure we are using en as the default Locale so we can find the resource
Locale
.
setDefault
(
Locale
.
ENGLISH
);
String
testClasses
=
System
.
getProperty
(
"test.classes"
);
System
.
out
.
println
(
"test.classes = "
+
testClasses
);
ClassLoader
myClassLoader
=
ClassLoader
.
getSystemClassLoader
();
// Find out where we are running from so we can setup the URLClassLoader URL
String
userDir
=
System
.
getProperty
(
"user.dir"
);
String
testDir
=
System
.
getProperty
(
"test.src"
,
userDir
);
String
sep
=
System
.
getProperty
(
"file.separator"
);
URL
[]
urls
=
new
URL
[
1
];
urls
[
0
]
=
Paths
.
get
(
testDir
,
"resources"
).
toUri
().
toURL
();
URLClassLoader
rbClassLoader
=
new
URLClassLoader
(
urls
);
// Test 1 - can we find a Logger bundle from doing a stack search?
// We shouldn't be able to
assertFalse
(
testGetBundleFromStackSearch
(),
"testGetBundleFromStackSearch"
);
// Test 2 - can we find a Logger bundle off of the Thread context class
// loader? We should be able to.
assertTrue
(
testGetBundleFromTCCL
(
TCCL_TEST_BUNDLE
,
rbClassLoader
),
"testGetBundleFromTCCL"
);
// Test 3 - Can we find a Logger bundle from the classpath? We should be
// able to, but ....
// We check to see if the bundle is on the classpath or not so that this
// will work standalone. In the case of jtreg/samevm,
// the resource bundles are not on the classpath. Running standalone
// (or othervm), they are
if
(
isOnClassPath
(
PROP_RB_NAME
,
myClassLoader
))
{
debug
(
"We should be able to see "
+
PROP_RB_NAME
+
" on the classpath"
);
assertTrue
(
testGetBundleFromSystemClassLoader
(
PROP_RB_NAME
),
"testGetBundleFromSystemClassLoader"
);
}
else
{
debug
(
"We should not be able to see "
+
PROP_RB_NAME
+
" on the classpath"
);
assertFalse
(
testGetBundleFromSystemClassLoader
(
PROP_RB_NAME
),
"testGetBundleFromSystemClassLoader"
);
}
report
();
}
private
void
report
()
throws
Exception
{
System
.
out
.
println
(
"Num passed = "
+
numPass
+
" Num failed = "
+
numFail
);
if
(
numFail
>
0
)
{
// We only care about the messages if they were errors
for
(
String
msg
:
msgs
)
{
System
.
out
.
println
(
msg
);
}
throw
new
Exception
(
numFail
+
" out of "
+
(
numPass
+
numFail
)
+
" tests failed."
);
}
}
public
void
assertTrue
(
boolean
testResult
,
String
testName
)
{
if
(
testResult
)
{
numPass
++;
}
else
{
numFail
++;
System
.
out
.
println
(
"FAILED: "
+
testName
+
" was supposed to return true but did NOT!"
);
}
}
public
void
assertFalse
(
boolean
testResult
,
String
testName
)
{
if
(!
testResult
)
{
numPass
++;
}
else
{
numFail
++;
System
.
out
.
println
(
"FAILED: "
+
testName
+
" was supposed to return false but did NOT!"
);
}
}
public
boolean
testGetBundleFromStackSearch
()
throws
Throwable
{
// This should fail. This was the old functionality to search up the
// caller's call stack
IndirectlyLoadABundle
indirectLoader
=
new
IndirectlyLoadABundle
();
return
indirectLoader
.
loadAndTest
();
}
public
boolean
testGetBundleFromTCCL
(
String
bundleName
,
ClassLoader
setOnTCCL
)
throws
InterruptedException
{
// This should succeed. We should be able to get the bundle from the
// thread context class loader
debug
(
"Looking for "
+
bundleName
+
" using TCCL"
);
LoggingThread
lr
=
new
LoggingThread
(
bundleName
,
setOnTCCL
);
lr
.
start
();
synchronized
(
lr
)
{
try
{
lr
.
wait
();
}
catch
(
InterruptedException
ex
)
{
throw
ex
;
}
}
msgs
.
add
(
lr
.
msg
);
return
lr
.
foundBundle
;
}
/*
* @param String bundleClass
* @param ClassLoader to use for search
* @return true iff bundleClass is on system classpath
*/
public
static
boolean
isOnClassPath
(
String
baseName
,
ClassLoader
cl
)
{
ResourceBundle
rb
=
null
;
try
{
rb
=
ResourceBundle
.
getBundle
(
baseName
,
Locale
.
getDefault
(),
cl
);
System
.
out
.
println
(
"INFO: Found bundle "
+
baseName
+
" on "
+
cl
);
}
catch
(
MissingResourceException
e
)
{
System
.
out
.
println
(
"INFO: Could not find bundle "
+
baseName
+
" on "
+
cl
);
return
false
;
}
return
(
rb
!=
null
);
}
private
static
String
newLoggerName
()
{
// we need a new logger name every time we attempt to find a bundle via
// the Logger.getLogger call, so we'll simply tack on an integer which
// we increment each time this is called
loggerNum
++;
return
LOGGER_PREFIX
+
loggerNum
;
}
public
boolean
testGetBundleFromSystemClassLoader
(
String
bundleName
)
{
// this should succeed if the bundle is on the system classpath.
try
{
Logger
aLogger
=
Logger
.
getLogger
(
ResourceBundleSearchTest
.
newLoggerName
(),
bundleName
);
}
catch
(
MissingResourceException
re
)
{
msgs
.
add
(
"INFO: testGetBundleFromSystemClassLoader() did not find bundle "
+
bundleName
);
return
false
;
}
msgs
.
add
(
"INFO: testGetBundleFromSystemClassLoader() found the bundle "
+
bundleName
);
return
true
;
}
public
static
class
LoggingThread
extends
Thread
{
boolean
foundBundle
=
false
;
String
msg
=
null
;
ClassLoader
clToSetOnTCCL
=
null
;
String
bundleName
=
null
;
public
LoggingThread
(
String
bundleName
)
{
this
.
bundleName
=
bundleName
;
}
public
LoggingThread
(
String
bundleName
,
ClassLoader
setOnTCCL
)
{
this
.
clToSetOnTCCL
=
setOnTCCL
;
this
.
bundleName
=
bundleName
;
}
public
void
run
()
{
boolean
setTCCL
=
false
;
try
{
if
(
clToSetOnTCCL
!=
null
)
{
Thread
.
currentThread
().
setContextClassLoader
(
clToSetOnTCCL
);
setTCCL
=
true
;
}
// this should succeed if the bundle is on the system classpath.
try
{
Logger
aLogger
=
Logger
.
getLogger
(
ResourceBundleSearchTest
.
newLoggerName
(),
bundleName
);
msg
=
"INFO: LoggingRunnable() found the bundle "
+
bundleName
+
(
setTCCL
?
" with "
:
" without "
)
+
"setting the TCCL"
;
foundBundle
=
true
;
}
catch
(
MissingResourceException
re
)
{
msg
=
"INFO: LoggingRunnable() did not find the bundle "
+
bundleName
+
(
setTCCL
?
" with "
:
" without "
)
+
"setting the TCCL"
;
foundBundle
=
false
;
}
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
System
.
exit
(
1
);
}
}
}
private
void
debug
(
String
msg
)
{
if
(
DEBUG
)
{
System
.
out
.
println
(
msg
);
}
}
}
test/java/util/logging/bundlesearch/resources/ContextClassLoaderTestBundle_en.properties
0 → 100644
浏览文件 @
d082dd79
#
# Copyright (c) 2013, 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.
#
sample1
=
translation #3 for sample1
sample2
=
translation #3 for sample2
supports-test
=
ResourceBundleSearchTest
test/java/util/logging/bundlesearch/resources/StackSearchableResource_en.properties
0 → 100644
浏览文件 @
d082dd79
#
# Copyright (c) 2013, 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.
#
sample1
=
translation #4 for sample1
sample2
=
translation #4 for sample2
supports-test
=
ResourceBundleSearchTest
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录