Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
f54995e6
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看板
提交
f54995e6
编写于
6月 19, 2012
作者:
C
chegar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6901992: InvalidJarIndexException due to bug in sun.misc.JarIndex.merge()
Reviewed-by: chegar Contributed-by: dbelfer@gmail.com
上级
6485051e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
349 addition
and
19 deletion
+349
-19
src/share/classes/sun/misc/JarIndex.java
src/share/classes/sun/misc/JarIndex.java
+11
-19
test/sun/misc/JarIndex/JarIndexMergeForClassLoaderTest.java
test/sun/misc/JarIndex/JarIndexMergeForClassLoaderTest.java
+222
-0
test/sun/misc/JarIndex/JarIndexMergeTest.java
test/sun/misc/JarIndex/JarIndexMergeTest.java
+116
-0
未找到文件。
src/share/classes/sun/misc/JarIndex.java
浏览文件 @
f54995e6
...
@@ -201,23 +201,20 @@ public class JarIndex {
...
@@ -201,23 +201,20 @@ public class JarIndex {
packageName
=
fileName
;
packageName
=
fileName
;
}
}
// add the mapping to indexMap
addMapping
(
packageName
,
jarName
);
addToList
(
packageName
,
jarName
,
indexMap
);
// add the mapping to jarMap
addToList
(
jarName
,
packageName
,
jarMap
);
}
}
/**
/**
* Same as add(String,String) except that it doesn't strip off from the
* Same as add(String,String) except that it doesn't strip off from the
* last index of '/'. It just adds the filename.
* last index of '/'. It just adds the jarItem (filename or package)
* as it is received.
*/
*/
private
void
add
Explicit
(
String
fileName
,
String
jarName
)
{
private
void
add
Mapping
(
String
jarItem
,
String
jarName
)
{
// add the mapping to indexMap
// add the mapping to indexMap
addToList
(
fileName
,
jarName
,
indexMap
);
addToList
(
jarItem
,
jarName
,
indexMap
);
// add the mapping to jarMap
// add the mapping to jarMap
addToList
(
jarName
,
fileName
,
jarMap
);
addToList
(
jarName
,
jarItem
,
jarMap
);
}
}
/**
/**
...
@@ -248,18 +245,14 @@ public class JarIndex {
...
@@ -248,18 +245,14 @@ public class JarIndex {
fileName
.
equals
(
JarFile
.
MANIFEST_NAME
))
fileName
.
equals
(
JarFile
.
MANIFEST_NAME
))
continue
;
continue
;
if
(!
metaInfFilenames
)
{
if
(!
metaInfFilenames
||
!
fileName
.
startsWith
(
"META-INF/"
))
{
add
(
fileName
,
currentJar
);
}
else
{
if
(!
fileName
.
startsWith
(
"META-INF/"
))
{
add
(
fileName
,
currentJar
);
add
(
fileName
,
currentJar
);
}
else
if
(!
entry
.
isDirectory
())
{
}
else
if
(!
entry
.
isDirectory
())
{
// Add files under META-INF explicitly so that certain
// Add files under META-INF explicitly so that certain
// services, like ServiceLoader, etc, can be located
// services, like ServiceLoader, etc, can be located
// with greater accuracy. Directories can be skipped
// with greater accuracy. Directories can be skipped
// since each file will be added explicitly.
// since each file will be added explicitly.
addExplicit
(
fileName
,
currentJar
);
addMapping
(
fileName
,
currentJar
);
}
}
}
}
}
...
@@ -324,8 +317,7 @@ public class JarIndex {
...
@@ -324,8 +317,7 @@ public class JarIndex {
jars
.
add
(
currentJar
);
jars
.
add
(
currentJar
);
}
else
{
}
else
{
String
name
=
line
;
String
name
=
line
;
addToList
(
name
,
currentJar
,
indexMap
);
addMapping
(
name
,
currentJar
);
addToList
(
currentJar
,
name
,
jarMap
);
}
}
}
}
...
@@ -354,7 +346,7 @@ public class JarIndex {
...
@@ -354,7 +346,7 @@ public class JarIndex {
if
(
path
!=
null
)
{
if
(
path
!=
null
)
{
jarName
=
path
.
concat
(
jarName
);
jarName
=
path
.
concat
(
jarName
);
}
}
toIndex
.
add
(
packageName
,
jarName
);
toIndex
.
add
Mapping
(
packageName
,
jarName
);
}
}
}
}
}
}
...
...
test/sun/misc/JarIndex/JarIndexMergeForClassLoaderTest.java
0 → 100644
浏览文件 @
f54995e6
/*
* Copyright (c) 2012, 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 6901992
* @summary InvalidJarIndexException due to bug in sun.misc.JarIndex.merge()
* Test URLClassLoader usage of the merge method when using indexes
* @author Diego Belfer
*/
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarOutputStream
;
public
class
JarIndexMergeForClassLoaderTest
{
static
final
String
slash
=
File
.
separator
;
static
final
String
testClassesDir
=
System
.
getProperty
(
"test.classes"
,
"."
);
static
final
String
jar
;
static
final
boolean
debug
=
true
;
static
final
File
tmpFolder
=
new
File
(
testClassesDir
);
static
{
String
javaHome
=
System
.
getProperty
(
"java.home"
);
if
(
javaHome
.
endsWith
(
"jre"
))
{
int
index
=
javaHome
.
lastIndexOf
(
slash
);
if
(
index
!=
-
1
)
javaHome
=
javaHome
.
substring
(
0
,
index
);
}
jar
=
javaHome
+
slash
+
"bin"
+
slash
+
"jar"
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// Create the jars file
File
jar1
=
buildJar1
();
File
jar2
=
buildJar2
();
File
jar3
=
buildJar3
();
// Index jar files in two levels: jar1 -> jar2 -> jar3
createIndex
(
jar2
.
getName
(),
jar3
.
getName
());
createIndex
(
jar1
.
getName
(),
jar2
.
getName
());
// Get root jar of the URLClassLoader
URL
url
=
jar1
.
toURI
().
toURL
();
URLClassLoader
classLoader
=
new
URLClassLoader
(
new
URL
[]
{
url
});
assertResource
(
classLoader
,
"com/jar1/resource.file"
,
"jar1"
);
assertResource
(
classLoader
,
"com/test/resource1.file"
,
"resource1"
);
assertResource
(
classLoader
,
"com/jar2/resource.file"
,
"jar2"
);
assertResource
(
classLoader
,
"com/test/resource2.file"
,
"resource2"
);
assertResource
(
classLoader
,
"com/test/resource3.file"
,
"resource3"
);
/*
* The following two asserts failed before the fix of the bug 6901992
*/
// Check that an existing file is found using the merged index
assertResource
(
classLoader
,
"com/missing/jar3/resource.file"
,
"jar3"
);
// Check that a non existent file in directory which does not contain
// any file is not found and it does not throw InvalidJarIndexException
assertResource
(
classLoader
,
"com/missing/nofile"
,
null
);
}
private
static
File
buildJar3
()
throws
FileNotFoundException
,
IOException
{
JarBuilder
jar3Builder
=
new
JarBuilder
(
tmpFolder
,
"jar3.jar"
);
jar3Builder
.
addResourceFile
(
"com/test/resource3.file"
,
"resource3"
);
jar3Builder
.
addResourceFile
(
"com/missing/jar3/resource.file"
,
"jar3"
);
return
jar3Builder
.
build
();
}
private
static
File
buildJar2
()
throws
FileNotFoundException
,
IOException
{
JarBuilder
jar2Builder
=
new
JarBuilder
(
tmpFolder
,
"jar2.jar"
);
jar2Builder
.
addResourceFile
(
"com/jar2/resource.file"
,
"jar2"
);
jar2Builder
.
addResourceFile
(
"com/test/resource2.file"
,
"resource2"
);
return
jar2Builder
.
build
();
}
private
static
File
buildJar1
()
throws
FileNotFoundException
,
IOException
{
JarBuilder
jar1Builder
=
new
JarBuilder
(
tmpFolder
,
"jar1.jar"
);
jar1Builder
.
addResourceFile
(
"com/jar1/resource.file"
,
"jar1"
);
jar1Builder
.
addResourceFile
(
"com/test/resource1.file"
,
"resource1"
);
return
jar1Builder
.
build
();
}
/* create the index */
static
void
createIndex
(
String
parentJar
,
String
childJar
)
{
// ProcessBuilder is used so that the current directory can be set
// to the directory that directly contains the jars.
debug
(
"Running jar to create the index for: "
+
parentJar
+
" and "
+
childJar
);
ProcessBuilder
pb
=
new
ProcessBuilder
(
jar
,
"-i"
,
parentJar
,
childJar
);
pb
.
directory
(
tmpFolder
);
// pd.inheritIO();
try
{
Process
p
=
pb
.
start
();
if
(
p
.
waitFor
()
!=
0
)
throw
new
RuntimeException
(
"jar indexing failed"
);
if
(
debug
&&
p
!=
null
)
{
debugStream
(
p
.
getInputStream
());
debugStream
(
p
.
getErrorStream
());
}
}
catch
(
InterruptedException
|
IOException
x
)
{
throw
new
RuntimeException
(
x
);
}
}
private
static
void
debugStream
(
InputStream
is
)
throws
IOException
{
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
is
)))
{
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
debug
(
line
);
}
}
}
private
static
void
assertResource
(
URLClassLoader
classLoader
,
String
file
,
String
expectedContent
)
throws
IOException
{
InputStream
fileStream
=
classLoader
.
getResourceAsStream
(
file
);
if
(
fileStream
==
null
&&
expectedContent
==
null
)
{
return
;
}
if
(
fileStream
==
null
&&
expectedContent
!=
null
)
{
throw
new
RuntimeException
(
buildMessage
(
file
,
expectedContent
,
null
));
}
try
{
String
actualContent
=
readAsString
(
fileStream
);
if
(
fileStream
!=
null
&&
expectedContent
==
null
)
{
throw
new
RuntimeException
(
buildMessage
(
file
,
null
,
actualContent
));
}
if
(!
expectedContent
.
equals
(
actualContent
))
{
throw
new
RuntimeException
(
buildMessage
(
file
,
expectedContent
,
actualContent
));
}
}
finally
{
fileStream
.
close
();
}
}
private
static
String
buildMessage
(
String
file
,
String
expectedContent
,
String
actualContent
)
{
return
"Expected: "
+
expectedContent
+
" for: "
+
file
+
" was: "
+
actualContent
;
}
private
static
String
readAsString
(
InputStream
fileStream
)
throws
IOException
{
byte
[]
buffer
=
new
byte
[
1024
];
int
count
,
len
=
0
;
while
((
count
=
fileStream
.
read
(
buffer
,
len
,
buffer
.
length
-
len
))
!=
-
1
)
len
+=
count
;
return
new
String
(
buffer
,
0
,
len
,
"ASCII"
);
}
static
void
debug
(
Object
message
)
{
if
(
debug
)
System
.
out
.
println
(
message
);
}
/*
* Helper class for building jar files
*/
public
static
class
JarBuilder
{
private
JarOutputStream
os
;
private
File
jarFile
;
public
JarBuilder
(
File
tmpFolder
,
String
jarName
)
throws
FileNotFoundException
,
IOException
{
this
.
jarFile
=
new
File
(
tmpFolder
,
jarName
);
this
.
os
=
new
JarOutputStream
(
new
FileOutputStream
(
jarFile
));
}
public
void
addResourceFile
(
String
pathFromRoot
,
String
content
)
throws
IOException
{
JarEntry
entry
=
new
JarEntry
(
pathFromRoot
);
os
.
putNextEntry
(
entry
);
os
.
write
(
content
.
getBytes
(
"ASCII"
));
os
.
closeEntry
();
}
public
File
build
()
throws
IOException
{
os
.
close
();
return
jarFile
;
}
}
}
test/sun/misc/JarIndex/JarIndexMergeTest.java
0 → 100644
浏览文件 @
f54995e6
/*
* Copyright (c) 2012, 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 6901992
* @compile -XDignore.symbol.file JarIndexMergeTest.java
* @run main JarIndexMergeTest
* @summary InvalidJarIndexException due to bug in sun.misc.JarIndex.merge()
* @author Diego Belfer
*/
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.util.LinkedList
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarOutputStream
;
// implementation specific API
import
sun.misc.JarIndex
;
public
class
JarIndexMergeTest
{
static
final
String
slash
=
File
.
separator
;
static
final
String
testClassesDir
=
System
.
getProperty
(
"test.classes"
,
"."
);
static
final
File
tmpFolder
=
new
File
(
testClassesDir
);
public
static
void
main
(
String
[]
args
)
throws
Exception
{
File
jar1
=
buildJar1
();
File
jar2
=
buildJar2
();
JarIndex
jarIndex1
=
new
JarIndex
(
new
String
[]
{
jar1
.
getAbsolutePath
()
});
JarIndex
jarIndex2
=
new
JarIndex
(
new
String
[]
{
jar2
.
getAbsolutePath
()
});
jarIndex1
.
merge
(
jarIndex2
,
null
);
assertFileResolved
(
jarIndex2
,
"com/test1/resource1.file"
,
jar1
.
getAbsolutePath
());
assertFileResolved
(
jarIndex2
,
"com/test2/resource2.file"
,
jar2
.
getAbsolutePath
());
}
static
void
assertFileResolved
(
JarIndex
jarIndex2
,
String
file
,
String
jarName
)
{
@SuppressWarnings
(
"unchecked"
)
LinkedList
<
String
>
jarLists
=
(
LinkedList
<
String
>)
jarIndex2
.
get
(
file
);
if
(
jarLists
==
null
||
jarLists
.
size
()
==
0
||
!
jarName
.
equals
(
jarLists
.
get
(
0
)))
{
throw
new
RuntimeException
(
"Unexpected result: the merged index must resolve file: "
+
file
);
}
}
private
static
File
buildJar1
()
throws
FileNotFoundException
,
IOException
{
JarBuilder
jar1Builder
=
new
JarBuilder
(
tmpFolder
,
"jar1-merge.jar"
);
jar1Builder
.
addResourceFile
(
"com/test1/resource1.file"
,
"resource1"
);
return
jar1Builder
.
build
();
}
private
static
File
buildJar2
()
throws
FileNotFoundException
,
IOException
{
JarBuilder
jar2Builder
=
new
JarBuilder
(
tmpFolder
,
"jar2-merge.jar"
);
jar2Builder
.
addResourceFile
(
"com/test2/resource2.file"
,
"resource2"
);
return
jar2Builder
.
build
();
}
/*
* Helper class for building jar files
*/
public
static
class
JarBuilder
{
private
JarOutputStream
os
;
private
File
jarFile
;
public
JarBuilder
(
File
tmpFolder
,
String
jarName
)
throws
FileNotFoundException
,
IOException
{
this
.
jarFile
=
new
File
(
tmpFolder
,
jarName
);
this
.
os
=
new
JarOutputStream
(
new
FileOutputStream
(
jarFile
));
}
public
void
addResourceFile
(
String
pathFromRoot
,
String
content
)
throws
IOException
{
JarEntry
entry
=
new
JarEntry
(
pathFromRoot
);
os
.
putNextEntry
(
entry
);
os
.
write
(
content
.
getBytes
(
"ASCII"
));
os
.
closeEntry
();
}
public
File
build
()
throws
IOException
{
os
.
close
();
return
jarFile
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录