Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
59d00fca
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看板
提交
59d00fca
编写于
4月 18, 2011
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
7030649: URL.equals() fails to compare jar urls
Reviewed-by: michaelm
上级
7ccadbc7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
150 addition
and
9 deletion
+150
-9
src/share/classes/sun/net/www/protocol/jar/Handler.java
src/share/classes/sun/net/www/protocol/jar/Handler.java
+72
-4
test/java/net/URL/Equals.java
test/java/net/URL/Equals.java
+78
-5
未找到文件。
src/share/classes/sun/net/www/protocol/jar/Handler.java
浏览文件 @
59d00fca
/*
* Copyright (c) 1997, 20
00
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 20
11
, 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
...
...
@@ -25,9 +25,8 @@
package
sun.net.www.protocol.jar
;
import
java.io.
*
;
import
java.io.
IOException
;
import
java.net.*
;
import
java.util.*
;
import
sun.net.www.ParseUtil
;
/*
...
...
@@ -42,7 +41,7 @@ public class Handler extends java.net.URLStreamHandler {
return
new
JarURLConnection
(
u
,
this
);
}
private
int
indexOfBangSlash
(
String
spec
)
{
private
static
int
indexOfBangSlash
(
String
spec
)
{
int
indexOfBang
=
spec
.
length
();
while
((
indexOfBang
=
spec
.
lastIndexOf
(
'!'
,
indexOfBang
))
!=
-
1
)
{
if
((
indexOfBang
!=
(
spec
.
length
()
-
1
))
&&
...
...
@@ -55,6 +54,75 @@ public class Handler extends java.net.URLStreamHandler {
return
-
1
;
}
/**
* Compare two jar URLs
*/
@Override
protected
boolean
sameFile
(
URL
u1
,
URL
u2
)
{
if
(!
u1
.
getProtocol
().
equals
(
"jar"
)
||
!
u2
.
getProtocol
().
equals
(
"jar"
))
return
false
;
String
file1
=
u1
.
getFile
();
String
file2
=
u2
.
getFile
();
int
sep1
=
file1
.
indexOf
(
separator
);
int
sep2
=
file2
.
indexOf
(
separator
);
if
(
sep1
==
-
1
||
sep2
==
-
1
)
{
return
super
.
sameFile
(
u1
,
u2
);
}
String
entry1
=
file1
.
substring
(
sep1
+
2
);
String
entry2
=
file2
.
substring
(
sep2
+
2
);
if
(!
entry1
.
equals
(
entry2
))
return
false
;
URL
enclosedURL1
=
null
,
enclosedURL2
=
null
;
try
{
enclosedURL1
=
new
URL
(
file1
.
substring
(
0
,
sep1
));
enclosedURL2
=
new
URL
(
file2
.
substring
(
0
,
sep2
));
}
catch
(
MalformedURLException
unused
)
{
return
super
.
sameFile
(
u1
,
u2
);
}
if
(!
super
.
sameFile
(
enclosedURL1
,
enclosedURL2
))
{
return
false
;
}
return
true
;
}
@Override
protected
int
hashCode
(
URL
u
)
{
int
h
=
0
;
String
protocol
=
u
.
getProtocol
();
if
(
protocol
!=
null
)
h
+=
protocol
.
hashCode
();
String
file
=
u
.
getFile
();
int
sep
=
file
.
indexOf
(
separator
);
if
(
sep
==
-
1
)
return
h
+
file
.
hashCode
();
URL
enclosedURL
=
null
;
String
fileWithoutEntry
=
file
.
substring
(
0
,
sep
);
try
{
enclosedURL
=
new
URL
(
fileWithoutEntry
);
h
+=
enclosedURL
.
hashCode
();
}
catch
(
MalformedURLException
unused
)
{
h
+=
fileWithoutEntry
.
hashCode
();
}
String
entry
=
file
.
substring
(
sep
+
2
);
h
+=
entry
.
hashCode
();
return
h
;
}
@Override
protected
void
parseURL
(
URL
url
,
String
spec
,
int
start
,
int
limit
)
{
String
file
=
null
;
...
...
test/java/net/URL/Equals.java
浏览文件 @
59d00fca
/*
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998,
2011,
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
...
...
@@ -23,16 +23,19 @@
/*
* @test
* @bug 4052976
* @summary Test URL.equals involving anchors
*
* @bug 4052976 7030649
* @summary Test URL.equals with anchors, and jar URLs
*/
import
java.net.*
;
public
class
Equals
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
anchors
();
jarURLs
();
}
static
void
anchors
()
throws
Exception
{
URL
url1
,
url2
;
url1
=
new
URL
(
null
,
"http://JavaSoft/Test#bar"
);
...
...
@@ -45,4 +48,74 @@ public class Equals {
if
(
url1
.
equals
(
null
))
throw
new
RuntimeException
(
"URL.equals fails given null"
);
}
static
final
String
HTTP_URL1A
=
"http://localhost/xyz"
;
static
final
String
HTTP_URL1B
=
"http://LOCALHOST/xyz"
;
static
final
String
FILE_URL1A
=
"file:///c:/foo/xyz"
;
static
final
String
FILE_URL1B
=
"file:/c:/foo/xyz"
;
static
void
jarURLs
()
throws
Exception
{
int
failed
=
0
;
failed
=
compareJarURLS
(
HTTP_URL1A
,
HTTP_URL1A
,
"!/abc"
,
"!/abc"
,
true
);
failed
=
compareJarURLS
(
HTTP_URL1A
,
HTTP_URL1B
,
"!/abc"
,
"!/abc"
,
true
);
failed
=
compareJarURLS
(
HTTP_URL1B
,
HTTP_URL1A
,
"!/"
,
"!/"
,
true
);
failed
=
compareJarURLS
(
HTTP_URL1A
,
HTTP_URL1B
,
"!/abc"
,
"!/"
,
false
);
failed
=
compareJarURLS
(
HTTP_URL1A
,
HTTP_URL1B
,
"!/abc"
,
"!/xy"
,
false
);
failed
=
compareJarURLS
(
FILE_URL1A
,
FILE_URL1A
,
"!/abc"
,
"!/abc"
,
true
);
failed
=
compareJarURLS
(
FILE_URL1A
,
FILE_URL1B
,
"!/abc"
,
"!/abc"
,
true
);
failed
=
compareJarURLS
(
FILE_URL1A
,
FILE_URL1B
,
"!/"
,
"!/"
,
true
);
failed
=
compareJarURLS
(
FILE_URL1A
,
FILE_URL1B
,
"!/abc"
,
"!/"
,
false
);
failed
=
compareJarURLS
(
FILE_URL1A
,
FILE_URL1B
,
"!/abc"
,
"!/xy"
,
false
);
failed
=
(
new
URL
(
"jar:file://xzy!/abc"
)).
equals
(
new
URL
(
"file://xzy!/abc"
))
?
1
:
0
;
if
(
failed
>
0
)
throw
new
RuntimeException
(
"Some jar URL tests failed. Check output"
);
}
static
int
compareJarURLS
(
String
urlStr1
,
String
urlStr2
,
String
entry1
,
String
entry2
,
boolean
expectEqual
)
throws
Exception
{
int
failed
=
0
;
URL
url1
=
new
URL
(
urlStr1
);
URL
url2
=
new
URL
(
urlStr2
);
if
(!
url1
.
equals
(
url2
))
{
System
.
out
.
println
(
"Urls are not equal, so the test cannot run."
);
System
.
out
.
println
(
"url1: "
+
url1
+
", url2:"
+
url2
);
return
1
;
}
URL
jarUrl1
=
new
URL
(
"jar:"
+
urlStr1
+
entry1
);
URL
jarUrl2
=
new
URL
(
"jar:"
+
urlStr2
+
entry2
);
jarUrl2
.
openConnection
();
boolean
equal
=
jarUrl1
.
equals
(
jarUrl2
);
if
(
expectEqual
&&
!
equal
)
{
System
.
out
.
println
(
"URLs should be equal, but are not. "
+
jarUrl1
+
", "
+
jarUrl2
);
failed
++;
}
else
if
(!
expectEqual
&&
equal
)
{
System
.
out
.
println
(
"URLs should NOT be equal, but are. "
+
jarUrl1
+
", "
+
jarUrl2
);
failed
++;
}
if
(
expectEqual
)
{
// hashCode MUST produce the same integer result for equal urls
int
hash1
=
jarUrl1
.
hashCode
();
int
hash2
=
jarUrl2
.
hashCode
();
if
(
hash1
!=
hash2
)
{
System
.
out
.
println
(
"jarUrl1.hashCode = "
+
hash1
);
System
.
out
.
println
(
"jarUrl2.hashCode = "
+
hash2
);
System
.
out
.
println
(
"Equal urls should have same hashCode. "
+
jarUrl1
+
", "
+
jarUrl2
);
failed
++;
}
}
return
failed
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录