Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
e754cced
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看板
提交
e754cced
编写于
12月 17, 2019
作者:
Z
zgu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8216401: Allow "file:" URLs in Class-Path of local JARs
Reviewed-by: phh, andrew
上级
9e1b748e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
173 addition
and
27 deletion
+173
-27
src/share/classes/sun/misc/URLClassPath.java
src/share/classes/sun/misc/URLClassPath.java
+70
-27
test/sun/misc/URLClassPath/JarClassPathFileEntry.java
test/sun/misc/URLClassPath/JarClassPathFileEntry.java
+103
-0
未找到文件。
src/share/classes/sun/misc/URLClassPath.java
浏览文件 @
e754cced
/*
/*
* Copyright (c) 1997, 201
8
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 201
9
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
*
* This code is free software; you can redistribute it and/or modify it
* This code is free software; you can redistribute it and/or modify it
...
@@ -1229,10 +1229,15 @@ public class URLClassPath {
...
@@ -1229,10 +1229,15 @@ public class URLClassPath {
int
i
=
0
;
int
i
=
0
;
while
(
st
.
hasMoreTokens
())
{
while
(
st
.
hasMoreTokens
())
{
String
path
=
st
.
nextToken
();
String
path
=
st
.
nextToken
();
URL
url
=
DISABLE_CP_URL_CHECK
?
new
URL
(
base
,
path
)
:
safe
Resolve
(
base
,
path
);
URL
url
=
DISABLE_CP_URL_CHECK
?
new
URL
(
base
,
path
)
:
try
Resolve
(
base
,
path
);
if
(
url
!=
null
)
{
if
(
url
!=
null
)
{
urls
[
i
]
=
url
;
urls
[
i
]
=
url
;
i
++;
i
++;
}
else
{
if
(
DEBUG_CP_URL_CHECK
)
{
System
.
err
.
println
(
"Class-Path entry: \""
+
path
+
"\" ignored in JAR file "
+
base
);
}
}
}
}
}
if
(
i
==
0
)
{
if
(
i
==
0
)
{
...
@@ -1244,18 +1249,50 @@ public class URLClassPath {
...
@@ -1244,18 +1249,50 @@ public class URLClassPath {
return
urls
;
return
urls
;
}
}
/*
static
URL
tryResolve
(
URL
base
,
String
input
)
throws
MalformedURLException
{
* Return a URL for the given path resolved against the base URL, or
if
(
"file"
.
equalsIgnoreCase
(
base
.
getProtocol
()))
{
* null if the resulting URL is invalid.
return
tryResolveFile
(
base
,
input
);
}
else
{
return
tryResolveNonFile
(
base
,
input
);
}
}
/**
* Attempt to return a file URL by resolving input against a base file
* URL. The input is an absolute or relative file URL that encodes a
* file path.
*
* @apiNote Nonsensical input such as a Windows file path with a drive
* letter cannot be disambiguated from an absolute URL so will be rejected
* (by returning null) by this method.
*
* @return the resolved URL or null if the input is an absolute URL with
* a scheme other than file (ignoring case)
* @throws MalformedURLException
*/
*/
static
URL
safeResolve
(
URL
base
,
String
path
)
{
static
URL
tryResolveFile
(
URL
base
,
String
input
)
throws
MalformedURLException
{
String
child
=
path
.
replace
(
File
.
separatorChar
,
'/'
);
int
index
=
input
.
indexOf
(
':'
);
try
{
boolean
isFile
;
if
(!
URI
.
create
(
child
).
isAbsolute
())
{
if
(
index
>=
0
)
{
URL
url
=
new
URL
(
base
,
child
);
String
scheme
=
input
.
substring
(
0
,
index
);
if
(
base
.
getProtocol
().
equalsIgnoreCase
(
"file"
))
{
isFile
=
"file"
.
equalsIgnoreCase
(
scheme
);
return
url
;
}
else
{
}
else
{
isFile
=
true
;
}
return
(
isFile
)
?
new
URL
(
base
,
input
)
:
null
;
}
/**
* Attempt to return a URL by resolving input against a base URL. Returns
* null if the resolved URL is not contained by the base URL.
*
* @return the resolved URL or null
* @throws MalformedURLException
*/
static
URL
tryResolveNonFile
(
URL
base
,
String
input
)
throws
MalformedURLException
{
String
child
=
input
.
replace
(
File
.
separatorChar
,
'/'
);
if
(
isRelative
(
child
))
{
URL
url
=
new
URL
(
base
,
child
);
String
bp
=
base
.
getPath
();
String
bp
=
base
.
getPath
();
String
urlp
=
url
.
getPath
();
String
urlp
=
url
.
getPath
();
int
pos
=
bp
.
lastIndexOf
(
'/'
);
int
pos
=
bp
.
lastIndexOf
(
'/'
);
...
@@ -1267,12 +1304,18 @@ public class URLClassPath {
...
@@ -1267,12 +1304,18 @@ public class URLClassPath {
return
url
;
return
url
;
}
}
}
}
return
null
;
}
}
}
catch
(
MalformedURLException
|
IllegalArgumentException
e
)
{}
if
(
DEBUG_CP_URL_CHECK
)
{
/**
System
.
err
.
println
(
"Class-Path entry: \""
+
path
+
"\" ignored in JAR file "
+
base
);
* Returns true if the given input is a relative URI.
*/
static
boolean
isRelative
(
String
child
)
{
try
{
return
!
URI
.
create
(
child
).
isAbsolute
();
}
catch
(
IllegalArgumentException
e
)
{
return
false
;
}
}
return
null
;
}
}
}
}
...
...
test/sun/misc/URLClassPath/JarClassPathFileEntry.java
0 → 100644
浏览文件 @
e754cced
/*
* Copyright (c) 2019, 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.io.File
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.jar.Attributes
;
import
java.util.jar.Manifest
;
import
jdk.testlibrary.InMemoryJavaCompiler
;
import
jdk.testlibrary.JarUtils
;
/*
* @test
* @bug 8216401
* @summary Test loading of JAR Class-Path entry with file: scheme
* @library /lib/testlibrary
*
* @run main/othervm JarClassPathFileEntry
* @run main/othervm -Djdk.net.URLClassPath.disableClassPathURLCheck=true JarClassPathFileEntry
* @run main/othervm -Djdk.net.URLClassPath.disableClassPathURLCheck=false JarClassPathFileEntry
*/
public
class
JarClassPathFileEntry
{
private
final
static
boolean
IS_WINDOWS
=
System
.
getProperty
(
"os.name"
).
startsWith
(
"Windows"
);
private
final
static
String
TEST_CLASSES
=
System
.
getProperty
(
"test.classes"
);
private
final
static
String
OTHER_DIR
=
TEST_CLASSES
+
"/OTHER/"
;
private
final
static
Path
OTHER_JAR_PATH
=
Paths
.
get
(
OTHER_DIR
,
"Other.jar"
);
private
final
static
Path
CONTEXT_JAR_PATH
=
Paths
.
get
(
TEST_CLASSES
,
"Context.jar"
);
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
// Create Other.class in OTHER_DIR, off the default classpath
byte
klassbuf
[]
=
InMemoryJavaCompiler
.
compile
(
"Other"
,
"public class Other {}"
);
ClassFileInstaller
.
writeClassToDisk
(
"Other"
,
klassbuf
,
OTHER_DIR
);
// Create Other.jar in OTHER_DIR
JarUtils
.
createJarFile
(
OTHER_JAR_PATH
,
Paths
.
get
(
OTHER_DIR
),
Paths
.
get
(
OTHER_DIR
,
"Other.class"
));
// Create Context.class
klassbuf
=
InMemoryJavaCompiler
.
compile
(
"Context"
,
"public class Context {}"
);
ClassFileInstaller
.
writeClassToDisk
(
"Context"
,
klassbuf
,
TEST_CLASSES
);
// Create Context.jar w/ "file:" entry for Other.jar
Manifest
mf
=
new
Manifest
();
Attributes
attrs
=
mf
.
getMainAttributes
();
attrs
.
put
(
Attributes
.
Name
.
MANIFEST_VERSION
,
"1.0"
);
String
classPathEntry
=
"file:"
+
(
IS_WINDOWS
?
toUnixPath
(
OTHER_JAR_PATH
.
toString
())
:
OTHER_JAR_PATH
.
toString
());
attrs
.
put
(
Attributes
.
Name
.
CLASS_PATH
,
classPathEntry
);
System
.
out
.
println
(
"Creating Context.jar with Class-Path: "
+
classPathEntry
);
JarUtils
.
createJarFile
(
CONTEXT_JAR_PATH
,
mf
,
Paths
.
get
(
TEST_CLASSES
),
Paths
.
get
(
TEST_CLASSES
,
"Context.class"
));
// Use URLClassLoader w/ Context.jar to load Other.class, which will
// load via the Class-Path entry
URL
url
=
CONTEXT_JAR_PATH
.
toUri
().
toURL
();
URLClassLoader
ucl
=
new
URLClassLoader
(
new
URL
[]{
url
},
null
);
// don't delegate to App CL
Class
<?>
otherClass
=
Class
.
forName
(
"Other"
,
true
,
ucl
);
// ClassNotFoundException -> fail
System
.
out
.
println
(
"Loaded: "
+
otherClass
);
}
/* Convert a Windows path to a unix-style path, and remove any drive letter */
private
static
String
toUnixPath
(
String
orig
)
{
String
retVal
=
new
File
(
orig
).
toURI
().
getPath
();
int
colonAt
=
retVal
.
indexOf
(
':'
);
if
(
colonAt
!=
-
1
&&
colonAt
<
3
)
{
retVal
=
retVal
.
substring
(
colonAt
+
1
);
// Start after the drive letter
}
return
retVal
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录