Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
a7cb2d41
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看板
提交
a7cb2d41
编写于
1月 30, 2009
作者:
T
tbell
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
400aca47
0e496345
变更
27
展开全部
隐藏空白更改
内联
并排
Showing
27 changed file
with
1477 addition
and
619 deletion
+1477
-619
src/share/classes/java/io/InputStream.java
src/share/classes/java/io/InputStream.java
+1
-1
src/share/classes/java/lang/Enum.java
src/share/classes/java/lang/Enum.java
+9
-4
src/share/classes/java/lang/Object.java
src/share/classes/java/lang/Object.java
+96
-96
src/share/classes/java/lang/RuntimePermission.java
src/share/classes/java/lang/RuntimePermission.java
+7
-0
src/share/classes/java/lang/annotation/Annotation.java
src/share/classes/java/lang/annotation/Annotation.java
+5
-1
src/share/classes/java/lang/instrument/package.html
src/share/classes/java/lang/instrument/package.html
+25
-0
src/share/classes/java/net/HttpCookie.java
src/share/classes/java/net/HttpCookie.java
+1
-2
src/share/classes/java/net/URLClassLoader.java
src/share/classes/java/net/URLClassLoader.java
+63
-6
src/share/classes/java/util/Formatter.java
src/share/classes/java/util/Formatter.java
+446
-446
src/share/classes/java/util/logging/Logger.java
src/share/classes/java/util/logging/Logger.java
+26
-35
src/share/classes/sun/misc/URLClassPath.java
src/share/classes/sun/misc/URLClassPath.java
+43
-18
src/solaris/native/java/lang/UNIXProcess_md.c
src/solaris/native/java/lang/UNIXProcess_md.c
+7
-1
test/java/lang/Enum/ValueOf.java
test/java/lang/Enum/ValueOf.java
+224
-0
test/java/lang/reflect/Generics/Probe.java
test/java/lang/reflect/Generics/Probe.java
+17
-4
test/java/net/CookieHandler/TestHttpCookie.java
test/java/net/CookieHandler/TestHttpCookie.java
+4
-5
test/java/net/URLClassLoader/closetest/CloseTest.java
test/java/net/URLClassLoader/closetest/CloseTest.java
+246
-0
test/java/net/URLClassLoader/closetest/README
test/java/net/URLClassLoader/closetest/README
+24
-0
test/java/net/URLClassLoader/closetest/build.sh
test/java/net/URLClassLoader/closetest/build.sh
+73
-0
test/java/net/URLClassLoader/closetest/serverRoot/Test.java
test/java/net/URLClassLoader/closetest/serverRoot/Test.java
+28
-0
test/java/net/URLClassLoader/closetest/test1/com/foo/Resource1
...java/net/URLClassLoader/closetest/test1/com/foo/Resource1
+1
-0
test/java/net/URLClassLoader/closetest/test1/com/foo/Resource2
...java/net/URLClassLoader/closetest/test1/com/foo/Resource2
+1
-0
test/java/net/URLClassLoader/closetest/test1/com/foo/TestClass.java
...net/URLClassLoader/closetest/test1/com/foo/TestClass.java
+38
-0
test/java/net/URLClassLoader/closetest/test1/com/foo/TestClass1.java
...et/URLClassLoader/closetest/test1/com/foo/TestClass1.java
+26
-0
test/java/net/URLClassLoader/closetest/test2/com/foo/Resource1
...java/net/URLClassLoader/closetest/test2/com/foo/Resource1
+1
-0
test/java/net/URLClassLoader/closetest/test2/com/foo/Resource2
...java/net/URLClassLoader/closetest/test2/com/foo/Resource2
+1
-0
test/java/net/URLClassLoader/closetest/test2/com/foo/TestClass.java
...net/URLClassLoader/closetest/test2/com/foo/TestClass.java
+38
-0
test/java/net/URLClassLoader/closetest/test2/com/foo/TestClass1.java
...et/URLClassLoader/closetest/test2/com/foo/TestClass1.java
+26
-0
未找到文件。
src/share/classes/java/io/InputStream.java
浏览文件 @
a7cb2d41
...
...
@@ -90,7 +90,7 @@ public abstract class InputStream implements Closeable {
*
* @param b the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> i
s
there is no more data because the end of
* <code>-1</code> i
f
there is no more data because the end of
* the stream has been reached.
* @exception IOException If the first byte cannot be read for any reason
* other than the end of the file, if the input stream has been closed, or
...
...
src/share/classes/java/lang/Enum.java
浏览文件 @
a7cb2d41
/*
* Copyright 2003-200
7
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-200
9
Sun Microsystems, Inc. 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
...
...
@@ -34,6 +34,11 @@ import java.io.ObjectStreamException;
/**
* This is the common base class of all Java language enumeration types.
*
* More information about enums, including implicit methods synthesised
* by the compiler, can be found in <i>The Java™ Language
* Specification, Third Edition</i>, <a
* href="http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9">§8.9</a>.
*
* @author Josh Bloch
* @author Neal Gafter
* @see Class#getEnumConstants()
...
...
@@ -212,7 +217,7 @@ public abstract class Enum<E extends Enum<E>>
if
(
name
==
null
)
throw
new
NullPointerException
(
"Name is null"
);
throw
new
IllegalArgumentException
(
"No enum const
"
+
enumType
+
"."
+
name
);
"No enum const
ant "
+
enumType
.
getCanonicalName
()
+
"."
+
name
);
}
/**
...
...
@@ -225,10 +230,10 @@ public abstract class Enum<E extends Enum<E>>
*/
private
void
readObject
(
ObjectInputStream
in
)
throws
IOException
,
ClassNotFoundException
{
throw
new
InvalidObjectException
(
"can't deserialize enum"
);
throw
new
InvalidObjectException
(
"can't deserialize enum"
);
}
private
void
readObjectNoData
()
throws
ObjectStreamException
{
throw
new
InvalidObjectException
(
"can't deserialize enum"
);
throw
new
InvalidObjectException
(
"can't deserialize enum"
);
}
}
src/share/classes/java/lang/Object.java
浏览文件 @
a7cb2d41
此差异已折叠。
点击以展开。
src/share/classes/java/lang/RuntimePermission.java
浏览文件 @
a7cb2d41
...
...
@@ -100,6 +100,13 @@ import java.util.StringTokenizer;
* </tr>
*
* <tr>
* <td>closeClassLoader</td>
* <td>Closing of a ClassLoader</td>
* <td>Granting this permission allows code to close any URLClassLoader
* that it has a reference to.</td>
* </tr>
*
* <tr>
* <td>setSecurityManager</td>
* <td>Setting of the security manager (possibly replacing an existing one)
* </td>
...
...
src/share/classes/java/lang/annotation/Annotation.java
浏览文件 @
a7cb2d41
/*
* Copyright 2003-200
4
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-200
9
Sun Microsystems, Inc. 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
...
...
@@ -31,6 +31,10 @@ package java.lang.annotation;
* an annotation type. Also note that this interface does not itself
* define an annotation type.
*
* More information about annotation types can be found in <i>The
* Java™ Language Specification, Third Edition</i>, <a
* href="http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.6">§9.6</a>.
*
* @author Josh Bloch
* @since 1.5
*/
...
...
src/share/classes/java/lang/instrument/package.html
浏览文件 @
a7cb2d41
<!--
Copyright 2003-2006 Sun Microsystems, Inc. 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. Sun designates this
particular file as subject to the "Classpath" exception as provided
by Sun in the LICENSE file that accompanied this code.
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
CA 95054 USA or visit www.sun.com if you need additional information or
have any questions.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
...
...
src/share/classes/java/net/HttpCookie.java
浏览文件 @
a7cb2d41
...
...
@@ -1058,8 +1058,7 @@ public final class HttpCookie implements Cloneable {
if
(
assignor
!=
null
)
{
assignor
.
assign
(
cookie
,
attrName
,
attrValue
);
}
else
{
// must be an error
throw
new
IllegalArgumentException
(
"Illegal cookie attribute"
);
// Ignore the attribute as per RFC 2965
}
}
...
...
src/share/classes/java/net/URLClassLoader.java
浏览文件 @
a7cb2d41
...
...
@@ -31,10 +31,12 @@ import java.io.File;
import
java.io.FilePermission
;
import
java.io.InputStream
;
import
java.io.IOException
;
import
java.io.Closeable
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.net.URLStreamHandlerFactory
;
import
java.util.Enumeration
;
import
java.util.List
;
import
java.util.NoSuchElementException
;
import
java.util.StringTokenizer
;
import
java.util.jar.Manifest
;
...
...
@@ -70,7 +72,7 @@ import sun.security.util.SecurityConstants;
* @author David Connelly
* @since 1.2
*/
public
class
URLClassLoader
extends
SecureClassLoader
{
public
class
URLClassLoader
extends
SecureClassLoader
implements
Closeable
{
/* The search path for classes and resources */
URLClassPath
ucp
;
...
...
@@ -85,13 +87,13 @@ public class URLClassLoader extends SecureClassLoader {
* to refer to a JAR file which will be downloaded and opened as needed.
*
* <p>If there is a security manager, this method first
* calls the security manager's
<code>checkCreateClassLoader</code>
method
* calls the security manager's
{@code checkCreateClassLoader}
method
* to ensure creation of a class loader is allowed.
*
* @param urls the URLs from which to load classes and resources
* @param parent the parent class loader for delegation
* @exception SecurityException if a security manager exists and its
*
<code>checkCreateClassLoader</code>
method doesn't allow
*
{@code checkCreateClassLoader}
method doesn't allow
* creation of a class loader.
* @see SecurityManager#checkCreateClassLoader
*/
...
...
@@ -169,12 +171,65 @@ public class URLClassLoader extends SecureClassLoader {
acc
=
AccessController
.
getContext
();
}
/**
* Closes this URLClassLoader, so that it can no longer be used to load
* new classes or resources that are defined by this loader.
* Classes and resources defined by any of this loader's parents in the
* delegation hierarchy are still accessible. Also, any classes or resources
* that are already loaded, are still accessible.
* <p>
* In the case of jar: and file: URLs, it also closes any class files,
* or JAR files that were opened by it. If another thread is loading a
* class when the {@code close} method is invoked, then the result of
* that load is undefined.
* <p>
* The method makes a best effort attempt to close all opened files,
* by catching {@link IOException}s internally. Unchecked exceptions
* and errors are not caught. Calling close on an already closed
* loader has no effect.
* <p>
* @throws IOException if closing any file opened by this class loader
* resulted in an IOException. Any such exceptions are caught, and a
* single IOException is thrown after the last file has been closed.
* If only one exception was thrown, it will be set as the <i>cause</i>
* of this IOException.
*
* @throws SecurityException if a security manager is set, and it denies
* {@link RuntimePermission}<tt>("closeClassLoader")</tt>
*
* @since 1.7
*/
public
void
close
()
throws
IOException
{
SecurityManager
security
=
System
.
getSecurityManager
();
if
(
security
!=
null
)
{
security
.
checkPermission
(
new
RuntimePermission
(
"closeClassLoader"
));
}
List
<
IOException
>
errors
=
ucp
.
closeLoaders
();
if
(
errors
.
isEmpty
())
{
return
;
}
if
(
errors
.
size
()
==
1
)
{
throw
new
IOException
(
"Error closing URLClassLoader resource"
,
errors
.
get
(
0
)
);
}
// Several exceptions. So, just combine the error messages
String
errormsg
=
"Error closing resources: "
;
for
(
IOException
error:
errors
)
{
errormsg
=
errormsg
+
"["
+
error
.
toString
()
+
"] "
;
}
throw
new
IOException
(
errormsg
);
}
/**
* Appends the specified URL to the list of URLs to search for
* classes and resources.
* <p>
* If the URL specified is <code>null</code> or is already in the
* list of URLs, then invoking this method has no effect.
* list of URLs, or if this loader is closed, then invoking this
* method has no effect.
*
* @param url the URL to be added to the search path of URLs
*/
...
...
@@ -199,7 +254,8 @@ public class URLClassLoader extends SecureClassLoader {
*
* @param name the name of the class
* @return the resulting class
* @exception ClassNotFoundException if the class could not be found
* @exception ClassNotFoundException if the class could not be found,
* or if the loader is closed.
*/
protected
Class
<?>
findClass
(
final
String
name
)
throws
ClassNotFoundException
...
...
@@ -370,7 +426,7 @@ public class URLClassLoader extends SecureClassLoader {
*
* @param name the name of the resource
* @return a <code>URL</code> for the resource, or <code>null</code>
* if the resource could not be found.
* if the resource could not be found
, or if the loader is closed
.
*/
public
URL
findResource
(
final
String
name
)
{
/*
...
...
@@ -393,6 +449,7 @@ public class URLClassLoader extends SecureClassLoader {
* @param name the resource name
* @exception IOException if an I/O exception occurs
* @return an <code>Enumeration</code> of <code>URL</code>s
* If the loader is closed, the Enumeration will be empty.
*/
public
Enumeration
<
URL
>
findResources
(
final
String
name
)
throws
IOException
...
...
src/share/classes/java/util/Formatter.java
浏览文件 @
a7cb2d41
此差异已折叠。
点击以展开。
src/share/classes/java/util/logging/Logger.java
浏览文件 @
a7cb2d41
...
...
@@ -27,6 +27,7 @@
package
java.util.logging
;
import
java.util.*
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.security.*
;
import
java.lang.ref.WeakReference
;
...
...
@@ -165,10 +166,11 @@ public class Logger {
private
static
final
int
offValue
=
Level
.
OFF
.
intValue
();
private
LogManager
manager
;
private
String
name
;
private
ArrayList
<
Handler
>
handlers
;
private
final
CopyOnWriteArrayList
<
Handler
>
handlers
=
new
CopyOnWriteArrayList
<
Handler
>();
private
String
resourceBundleName
;
private
boolean
useParentHandlers
=
true
;
private
Filter
filter
;
private
volatile
boolean
useParentHandlers
=
true
;
private
volatile
Filter
filter
;
private
boolean
anonymous
;
private
ResourceBundle
catalog
;
// Cached resource bundle
...
...
@@ -180,9 +182,9 @@ public class Logger {
private
static
Object
treeLock
=
new
Object
();
// We keep weak references from parents to children, but strong
// references from children to parents.
private
Logger
parent
;
// our nearest parent.
private
volatile
Logger
parent
;
// our nearest parent.
private
ArrayList
<
WeakReference
<
Logger
>>
kids
;
// WeakReferences to loggers that have us as parent
private
Level
levelObject
;
private
volatile
Level
levelObject
;
private
volatile
int
levelValue
;
// current effective level value
/**
...
...
@@ -438,7 +440,7 @@ public class Logger {
* @exception SecurityException if a security manager exists and if
* the caller does not have LoggingPermission("control").
*/
public
synchronized
void
setFilter
(
Filter
newFilter
)
throws
SecurityException
{
public
void
setFilter
(
Filter
newFilter
)
throws
SecurityException
{
checkAccess
();
filter
=
newFilter
;
}
...
...
@@ -448,7 +450,7 @@ public class Logger {
*
* @return a filter object (may be null)
*/
public
synchronized
Filter
getFilter
()
{
public
Filter
getFilter
()
{
return
filter
;
}
...
...
@@ -465,10 +467,9 @@ public class Logger {
if
(
record
.
getLevel
().
intValue
()
<
levelValue
||
levelValue
==
offValue
)
{
return
;
}
synchronized
(
this
)
{
if
(
filter
!=
null
&&
!
filter
.
isLoggable
(
record
))
{
return
;
}
Filter
theFilter
=
filter
;
if
(
theFilter
!=
null
&&
!
theFilter
.
isLoggable
(
record
))
{
return
;
}
// Post the LogRecord to all our Handlers, and then to
...
...
@@ -476,12 +477,8 @@ public class Logger {
Logger
logger
=
this
;
while
(
logger
!=
null
)
{
Handler
targets
[]
=
logger
.
getHandlers
();
if
(
targets
!=
null
)
{
for
(
int
i
=
0
;
i
<
targets
.
length
;
i
++)
{
targets
[
i
].
publish
(
record
);
}
for
(
Handler
handler
:
logger
.
handlers
)
{
handler
.
publish
(
record
);
}
if
(!
logger
.
getUseParentHandlers
())
{
...
...
@@ -1182,13 +1179,10 @@ public class Logger {
* @exception SecurityException if a security manager exists and if
* the caller does not have LoggingPermission("control").
*/
public
synchronized
void
addHandler
(
Handler
handler
)
throws
SecurityException
{
public
void
addHandler
(
Handler
handler
)
throws
SecurityException
{
// Check for null handler
handler
.
getClass
();
checkAccess
();
if
(
handlers
==
null
)
{
handlers
=
new
ArrayList
<
Handler
>();
}
handlers
.
add
(
handler
);
}
...
...
@@ -1201,14 +1195,11 @@ public class Logger {
* @exception SecurityException if a security manager exists and if
* the caller does not have LoggingPermission("control").
*/
public
synchronized
void
removeHandler
(
Handler
handler
)
throws
SecurityException
{
public
void
removeHandler
(
Handler
handler
)
throws
SecurityException
{
checkAccess
();
if
(
handler
==
null
)
{
return
;
}
if
(
handlers
==
null
)
{
return
;
}
handlers
.
remove
(
handler
);
}
...
...
@@ -1217,11 +1208,8 @@ public class Logger {
* <p>
* @return an array of all registered Handlers
*/
public
synchronized
Handler
[]
getHandlers
()
{
if
(
handlers
==
null
)
{
return
emptyHandlers
;
}
return
handlers
.
toArray
(
new
Handler
[
handlers
.
size
()]);
public
Handler
[]
getHandlers
()
{
return
handlers
.
toArray
(
emptyHandlers
);
}
/**
...
...
@@ -1235,7 +1223,7 @@ public class Logger {
* @exception SecurityException if a security manager exists and if
* the caller does not have LoggingPermission("control").
*/
public
synchronized
void
setUseParentHandlers
(
boolean
useParentHandlers
)
{
public
void
setUseParentHandlers
(
boolean
useParentHandlers
)
{
checkAccess
();
this
.
useParentHandlers
=
useParentHandlers
;
}
...
...
@@ -1246,7 +1234,7 @@ public class Logger {
*
* @return true if output is to be sent to the logger's parent
*/
public
synchronized
boolean
getUseParentHandlers
()
{
public
boolean
getUseParentHandlers
()
{
return
useParentHandlers
;
}
...
...
@@ -1354,9 +1342,12 @@ public class Logger {
* @return nearest existing parent Logger
*/
public
Logger
getParent
()
{
synchronized
(
treeLock
)
{
return
parent
;
}
// Note: this used to be synchronized on treeLock. However, this only
// provided memory semantics, as there was no guarantee that the caller
// would synchronize on treeLock (in fact, there is no way for external
// callers to so synchronize). Therefore, we have made parent volatile
// instead.
return
parent
;
}
/**
...
...
src/share/classes/sun/misc/URLClassPath.java
浏览文件 @
a7cb2d41
...
...
@@ -25,17 +25,7 @@
package
sun.misc
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.Hashtable
;
import
java.util.NoSuchElementException
;
import
java.util.Stack
;
import
java.util.Set
;
import
java.util.HashSet
;
import
java.util.StringTokenizer
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.*
;
import
java.util.jar.JarFile
;
import
sun.misc.JarIndex
;
import
sun.misc.InvalidJarIndexException
;
...
...
@@ -52,12 +42,7 @@ import java.net.URLConnection;
import
java.net.HttpURLConnection
;
import
java.net.URLStreamHandler
;
import
java.net.URLStreamHandlerFactory
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.*
;
import
java.security.AccessController
;
import
java.security.AccessControlException
;
import
java.security.CodeSigner
;
...
...
@@ -100,6 +85,9 @@ public class URLClassPath {
/* The jar protocol handler to use when creating new URLs */
private
URLStreamHandler
jarHandler
;
/* Whether this URLClassLoader has been closed yet */
private
boolean
closed
=
false
;
/**
* Creates a new URLClassPath for the given URLs. The URLs will be
* searched in the order specified for classes and resources. A URL
...
...
@@ -124,6 +112,22 @@ public class URLClassPath {
this
(
urls
,
null
);
}
public
synchronized
List
<
IOException
>
closeLoaders
()
{
if
(
closed
)
{
return
Collections
.
emptyList
();
}
List
<
IOException
>
result
=
new
LinkedList
<
IOException
>();
for
(
Loader
loader
:
loaders
)
{
try
{
loader
.
close
();
}
catch
(
IOException
e
)
{
result
.
add
(
e
);
}
}
closed
=
true
;
return
result
;
}
/**
* Appends the specified URL to the search path of directory and JAR
* file URLs from which to load classes and resources.
...
...
@@ -293,6 +297,9 @@ public class URLClassPath {
* if the specified index is out of range.
*/
private
synchronized
Loader
getLoader
(
int
index
)
{
if
(
closed
)
{
return
null
;
}
// Expand URL search path until the request can be satisfied
// or the URL stack is empty.
while
(
loaders
.
size
()
<
index
+
1
)
{
...
...
@@ -453,7 +460,7 @@ public class URLClassPath {
* Inner class used to represent a loader of resources and classes
* from a base URL.
*/
private
static
class
Loader
{
private
static
class
Loader
implements
Closeable
{
private
final
URL
base
;
/*
...
...
@@ -544,6 +551,12 @@ public class URLClassPath {
return
getResource
(
name
,
true
);
}
/*
* close this loader and release all resources
* method overridden in sub-classes
*/
public
void
close
()
throws
IOException
{}
/*
* Returns the local class path for this loader, or null if none.
*/
...
...
@@ -562,6 +575,7 @@ public class URLClassPath {
private
MetaIndex
metaIndex
;
private
URLStreamHandler
handler
;
private
HashMap
<
URL
,
Loader
>
lmap
;
private
boolean
closed
=
false
;
/*
* Creates a new JarLoader for the specified URL referring to
...
...
@@ -604,6 +618,17 @@ public class URLClassPath {
}
}
@Override
public
void
close
()
throws
IOException
{
// closing is synchronized at higher level
if
(!
closed
)
{
closed
=
true
;
// in case not already open.
ensureOpen
();
jar
.
close
();
}
}
JarFile
getJarFile
()
{
return
jar
;
}
...
...
src/solaris/native/java/lang/UNIXProcess_md.c
浏览文件 @
a7cb2d41
...
...
@@ -259,6 +259,12 @@ Java_java_lang_UNIXProcess_waitForProcessExit(JNIEnv* env,
}
}
static
int
isAsciiDigit
(
char
c
)
{
return
c
>=
'0'
&&
c
<=
'9'
;
}
static
int
closeDescriptors
(
void
)
{
...
...
@@ -284,7 +290,7 @@ closeDescriptors(void)
*/
while
((
dirp
=
readdir64
(
dp
))
!=
NULL
)
{
int
fd
;
if
(
is
d
igit
(
dirp
->
d_name
[
0
])
&&
if
(
is
AsciiD
igit
(
dirp
->
d_name
[
0
])
&&
(
fd
=
strtol
(
dirp
->
d_name
,
NULL
,
10
))
>=
from_fd
+
2
)
close
(
fd
);
}
...
...
test/java/lang/Enum/ValueOf.java
0 → 100644
浏览文件 @
a7cb2d41
/*
* Copyright 2004-2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4984908 5058132 6653154
* @summary Basic test of valueOf(String)
* @author Josh Bloch
*
* @compile ValueOf.java
* @run main ValueOf
*/
import
java.util.*
;
import
java.lang.reflect.Method
;
public
class
ValueOf
{
static
Random
rnd
=
new
Random
();
public
static
void
main
(
String
[]
args
)
throws
Exception
{
test
(
Silly0
.
class
);
test
(
Silly1
.
class
);
test
(
Silly31
.
class
);
test
(
Silly32
.
class
);
test
(
Silly33
.
class
);
test
(
Silly63
.
class
);
test
(
Silly64
.
class
);
test
(
Silly65
.
class
);
test
(
Silly127
.
class
);
test
(
Silly128
.
class
);
test
(
Silly129
.
class
);
test
(
Silly500
.
class
);
test
(
Specialized
.
class
);
testMissingException
();
}
static
<
T
extends
Enum
<
T
>>
void
test
(
Class
<
T
>
enumClass
)
throws
Exception
{
Set
<
T
>
s
=
EnumSet
.
allOf
(
enumClass
);
test
(
enumClass
,
s
);
// Delete half the elements from set at random
for
(
Iterator
<
T
>
i
=
s
.
iterator
();
i
.
hasNext
();
)
{
i
.
next
();
if
(
rnd
.
nextBoolean
())
i
.
remove
();
}
test
(
enumClass
,
s
);
}
static
<
T
extends
Enum
<
T
>>
void
test
(
Class
<
T
>
enumClass
,
Set
<
T
>
s
)
throws
Exception
{
Method
valueOf
=
enumClass
.
getDeclaredMethod
(
"valueOf"
,
String
.
class
);
Set
<
T
>
copy
=
EnumSet
.
noneOf
(
enumClass
);
for
(
T
e
:
s
)
copy
.
add
((
T
)
valueOf
.
invoke
(
null
,
e
.
name
()));
if
(!
copy
.
equals
(
s
))
throw
new
Exception
(
copy
+
" != "
+
s
);
}
static
void
testMissingException
()
{
try
{
Enum
.
valueOf
(
Specialized
.
class
,
"BAZ"
);
throw
new
RuntimeException
(
"Expected IllegalArgumentException not thrown."
);
}
catch
(
IllegalArgumentException
iae
)
{
String
message
=
iae
.
getMessage
();
if
(!
"No enum constant ValueOf.Specialized.BAZ"
.
equals
(
message
))
throw
new
RuntimeException
(
"Unexpected detail message: ``"
+
message
+
"''."
);
}
}
enum
Silly0
{
};
enum
Silly1
{
e1
}
enum
Silly31
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
}
enum
Silly32
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
}
enum
Silly33
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
}
enum
Silly63
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
,
e33
,
e34
,
e35
,
e36
,
e37
,
e38
,
e39
,
e40
,
e41
,
e42
,
e43
,
e44
,
e45
,
e46
,
e47
,
e48
,
e49
,
e50
,
e51
,
e52
,
e53
,
e54
,
e55
,
e56
,
e57
,
e58
,
e59
,
e60
,
e61
,
e62
}
enum
Silly64
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
,
e33
,
e34
,
e35
,
e36
,
e37
,
e38
,
e39
,
e40
,
e41
,
e42
,
e43
,
e44
,
e45
,
e46
,
e47
,
e48
,
e49
,
e50
,
e51
,
e52
,
e53
,
e54
,
e55
,
e56
,
e57
,
e58
,
e59
,
e60
,
e61
,
e62
,
e63
}
enum
Silly65
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
,
e33
,
e34
,
e35
,
e36
,
e37
,
e38
,
e39
,
e40
,
e41
,
e42
,
e43
,
e44
,
e45
,
e46
,
e47
,
e48
,
e49
,
e50
,
e51
,
e52
,
e53
,
e54
,
e55
,
e56
,
e57
,
e58
,
e59
,
e60
,
e61
,
e62
,
e63
,
e64
}
enum
Silly127
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
,
e33
,
e34
,
e35
,
e36
,
e37
,
e38
,
e39
,
e40
,
e41
,
e42
,
e43
,
e44
,
e45
,
e46
,
e47
,
e48
,
e49
,
e50
,
e51
,
e52
,
e53
,
e54
,
e55
,
e56
,
e57
,
e58
,
e59
,
e60
,
e61
,
e62
,
e63
,
e64
,
e65
,
e66
,
e67
,
e68
,
e69
,
e70
,
e71
,
e72
,
e73
,
e74
,
e75
,
e76
,
e77
,
e78
,
e79
,
e80
,
e81
,
e82
,
e83
,
e84
,
e85
,
e86
,
e87
,
e88
,
e89
,
e90
,
e91
,
e92
,
e93
,
e94
,
e95
,
e96
,
e97
,
e98
,
e99
,
e100
,
e101
,
e102
,
e103
,
e104
,
e105
,
e106
,
e107
,
e108
,
e109
,
e110
,
e111
,
e112
,
e113
,
e114
,
e115
,
e116
,
e117
,
e118
,
e119
,
e120
,
e121
,
e122
,
e123
,
e124
,
e125
,
e126
}
enum
Silly128
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
,
e33
,
e34
,
e35
,
e36
,
e37
,
e38
,
e39
,
e40
,
e41
,
e42
,
e43
,
e44
,
e45
,
e46
,
e47
,
e48
,
e49
,
e50
,
e51
,
e52
,
e53
,
e54
,
e55
,
e56
,
e57
,
e58
,
e59
,
e60
,
e61
,
e62
,
e63
,
e64
,
e65
,
e66
,
e67
,
e68
,
e69
,
e70
,
e71
,
e72
,
e73
,
e74
,
e75
,
e76
,
e77
,
e78
,
e79
,
e80
,
e81
,
e82
,
e83
,
e84
,
e85
,
e86
,
e87
,
e88
,
e89
,
e90
,
e91
,
e92
,
e93
,
e94
,
e95
,
e96
,
e97
,
e98
,
e99
,
e100
,
e101
,
e102
,
e103
,
e104
,
e105
,
e106
,
e107
,
e108
,
e109
,
e110
,
e111
,
e112
,
e113
,
e114
,
e115
,
e116
,
e117
,
e118
,
e119
,
e120
,
e121
,
e122
,
e123
,
e124
,
e125
,
e126
,
e127
}
enum
Silly129
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
,
e33
,
e34
,
e35
,
e36
,
e37
,
e38
,
e39
,
e40
,
e41
,
e42
,
e43
,
e44
,
e45
,
e46
,
e47
,
e48
,
e49
,
e50
,
e51
,
e52
,
e53
,
e54
,
e55
,
e56
,
e57
,
e58
,
e59
,
e60
,
e61
,
e62
,
e63
,
e64
,
e65
,
e66
,
e67
,
e68
,
e69
,
e70
,
e71
,
e72
,
e73
,
e74
,
e75
,
e76
,
e77
,
e78
,
e79
,
e80
,
e81
,
e82
,
e83
,
e84
,
e85
,
e86
,
e87
,
e88
,
e89
,
e90
,
e91
,
e92
,
e93
,
e94
,
e95
,
e96
,
e97
,
e98
,
e99
,
e100
,
e101
,
e102
,
e103
,
e104
,
e105
,
e106
,
e107
,
e108
,
e109
,
e110
,
e111
,
e112
,
e113
,
e114
,
e115
,
e116
,
e117
,
e118
,
e119
,
e120
,
e121
,
e122
,
e123
,
e124
,
e125
,
e126
,
e127
,
e128
}
enum
Silly500
{
e0
,
e1
,
e2
,
e3
,
e4
,
e5
,
e6
,
e7
,
e8
,
e9
,
e10
,
e11
,
e12
,
e13
,
e14
,
e15
,
e16
,
e17
,
e18
,
e19
,
e20
,
e21
,
e22
,
e23
,
e24
,
e25
,
e26
,
e27
,
e28
,
e29
,
e30
,
e31
,
e32
,
e33
,
e34
,
e35
,
e36
,
e37
,
e38
,
e39
,
e40
,
e41
,
e42
,
e43
,
e44
,
e45
,
e46
,
e47
,
e48
,
e49
,
e50
,
e51
,
e52
,
e53
,
e54
,
e55
,
e56
,
e57
,
e58
,
e59
,
e60
,
e61
,
e62
,
e63
,
e64
,
e65
,
e66
,
e67
,
e68
,
e69
,
e70
,
e71
,
e72
,
e73
,
e74
,
e75
,
e76
,
e77
,
e78
,
e79
,
e80
,
e81
,
e82
,
e83
,
e84
,
e85
,
e86
,
e87
,
e88
,
e89
,
e90
,
e91
,
e92
,
e93
,
e94
,
e95
,
e96
,
e97
,
e98
,
e99
,
e100
,
e101
,
e102
,
e103
,
e104
,
e105
,
e106
,
e107
,
e108
,
e109
,
e110
,
e111
,
e112
,
e113
,
e114
,
e115
,
e116
,
e117
,
e118
,
e119
,
e120
,
e121
,
e122
,
e123
,
e124
,
e125
,
e126
,
e127
,
e128
,
e129
,
e130
,
e131
,
e132
,
e133
,
e134
,
e135
,
e136
,
e137
,
e138
,
e139
,
e140
,
e141
,
e142
,
e143
,
e144
,
e145
,
e146
,
e147
,
e148
,
e149
,
e150
,
e151
,
e152
,
e153
,
e154
,
e155
,
e156
,
e157
,
e158
,
e159
,
e160
,
e161
,
e162
,
e163
,
e164
,
e165
,
e166
,
e167
,
e168
,
e169
,
e170
,
e171
,
e172
,
e173
,
e174
,
e175
,
e176
,
e177
,
e178
,
e179
,
e180
,
e181
,
e182
,
e183
,
e184
,
e185
,
e186
,
e187
,
e188
,
e189
,
e190
,
e191
,
e192
,
e193
,
e194
,
e195
,
e196
,
e197
,
e198
,
e199
,
e200
,
e201
,
e202
,
e203
,
e204
,
e205
,
e206
,
e207
,
e208
,
e209
,
e210
,
e211
,
e212
,
e213
,
e214
,
e215
,
e216
,
e217
,
e218
,
e219
,
e220
,
e221
,
e222
,
e223
,
e224
,
e225
,
e226
,
e227
,
e228
,
e229
,
e230
,
e231
,
e232
,
e233
,
e234
,
e235
,
e236
,
e237
,
e238
,
e239
,
e240
,
e241
,
e242
,
e243
,
e244
,
e245
,
e246
,
e247
,
e248
,
e249
,
e250
,
e251
,
e252
,
e253
,
e254
,
e255
,
e256
,
e257
,
e258
,
e259
,
e260
,
e261
,
e262
,
e263
,
e264
,
e265
,
e266
,
e267
,
e268
,
e269
,
e270
,
e271
,
e272
,
e273
,
e274
,
e275
,
e276
,
e277
,
e278
,
e279
,
e280
,
e281
,
e282
,
e283
,
e284
,
e285
,
e286
,
e287
,
e288
,
e289
,
e290
,
e291
,
e292
,
e293
,
e294
,
e295
,
e296
,
e297
,
e298
,
e299
,
e300
,
e301
,
e302
,
e303
,
e304
,
e305
,
e306
,
e307
,
e308
,
e309
,
e310
,
e311
,
e312
,
e313
,
e314
,
e315
,
e316
,
e317
,
e318
,
e319
,
e320
,
e321
,
e322
,
e323
,
e324
,
e325
,
e326
,
e327
,
e328
,
e329
,
e330
,
e331
,
e332
,
e333
,
e334
,
e335
,
e336
,
e337
,
e338
,
e339
,
e340
,
e341
,
e342
,
e343
,
e344
,
e345
,
e346
,
e347
,
e348
,
e349
,
e350
,
e351
,
e352
,
e353
,
e354
,
e355
,
e356
,
e357
,
e358
,
e359
,
e360
,
e361
,
e362
,
e363
,
e364
,
e365
,
e366
,
e367
,
e368
,
e369
,
e370
,
e371
,
e372
,
e373
,
e374
,
e375
,
e376
,
e377
,
e378
,
e379
,
e380
,
e381
,
e382
,
e383
,
e384
,
e385
,
e386
,
e387
,
e388
,
e389
,
e390
,
e391
,
e392
,
e393
,
e394
,
e395
,
e396
,
e397
,
e398
,
e399
,
e400
,
e401
,
e402
,
e403
,
e404
,
e405
,
e406
,
e407
,
e408
,
e409
,
e410
,
e411
,
e412
,
e413
,
e414
,
e415
,
e416
,
e417
,
e418
,
e419
,
e420
,
e421
,
e422
,
e423
,
e424
,
e425
,
e426
,
e427
,
e428
,
e429
,
e430
,
e431
,
e432
,
e433
,
e434
,
e435
,
e436
,
e437
,
e438
,
e439
,
e440
,
e441
,
e442
,
e443
,
e444
,
e445
,
e446
,
e447
,
e448
,
e449
,
e450
,
e451
,
e452
,
e453
,
e454
,
e455
,
e456
,
e457
,
e458
,
e459
,
e460
,
e461
,
e462
,
e463
,
e464
,
e465
,
e466
,
e467
,
e468
,
e469
,
e470
,
e471
,
e472
,
e473
,
e474
,
e475
,
e476
,
e477
,
e478
,
e479
,
e480
,
e481
,
e482
,
e483
,
e484
,
e485
,
e486
,
e487
,
e488
,
e489
,
e490
,
e491
,
e492
,
e493
,
e494
,
e495
,
e496
,
e497
,
e498
,
e499
}
enum
Specialized
{
FOO
{
public
void
foo
()
{}
};
abstract
public
void
foo
();
};
}
test/java/lang/reflect/Generics/Probe.java
浏览文件 @
a7cb2d41
...
...
@@ -23,7 +23,7 @@
/*
* @test
* @bug 5003916
* @bug 5003916
6704655
* @summary Testing parsing of signatures attributes of nested classes
* @author Joseph D. Darcy
* @compile -source 1.5 Probe.java
...
...
@@ -32,8 +32,10 @@
import
java.lang.reflect.*
;
import
java.lang.annotation.*
;
import
java.util.*
;
import
static
java
.
util
.
Arrays
.*;
@Classes
({
@Classes
(
value
=
{
"java.util.concurrent.FutureTask"
,
"java.util.concurrent.ConcurrentHashMap$EntryIterator"
,
"java.util.concurrent.ConcurrentHashMap$KeyIterator"
,
...
...
@@ -56,7 +58,9 @@ import java.lang.annotation.*;
"java.util.HashMap$ValueIterator"
,
"java.util.LinkedHashMap$EntryIterator"
,
"java.util.LinkedHashMap$KeyIterator"
,
"java.util.LinkedHashMap$ValueIterator"
,
"java.util.LinkedHashMap$ValueIterator"
},
sunClasses
={
"javax.crypto.SunJCE_c"
,
"javax.crypto.SunJCE_e"
,
"javax.crypto.SunJCE_f"
,
...
...
@@ -66,7 +70,15 @@ import java.lang.annotation.*;
})
public
class
Probe
{
public
static
void
main
(
String
[]
args
)
throws
Throwable
{
String
[]
names
=
(
Probe
.
class
).
getAnnotation
(
Classes
.
class
).
value
();
Classes
classesAnnotation
=
(
Probe
.
class
).
getAnnotation
(
Classes
.
class
);
List
<
String
>
names
=
new
ArrayList
<
String
>(
asList
(
classesAnnotation
.
value
()));
if
(
System
.
getProperty
(
"java.runtime.name"
).
startsWith
(
"Java(TM)"
))
{
// Sun production JDK; test crypto classes too
for
(
String
name:
classesAnnotation
.
sunClasses
())
names
.
add
(
name
);
}
int
errs
=
0
;
for
(
String
name:
names
)
{
...
...
@@ -140,4 +152,5 @@ public class Probe {
@Retention
(
RetentionPolicy
.
RUNTIME
)
@interface
Classes
{
String
[]
value
();
// list of classes to probe
String
[]
sunClasses
();
// list of Sun-production JDK specific classes to probe
}
test/java/net/CookieHandler/TestHttpCookie.java
浏览文件 @
a7cb2d41
...
...
@@ -24,7 +24,7 @@
/**
* @test
* @summary Unit test for java.net.HttpCookie
* @bug 6244040 6277796 6277801 6277808 6294071 6692802
* @bug 6244040 6277796 6277801 6277808 6294071 6692802
6790677
* @author Edward Wang
*/
...
...
@@ -278,10 +278,6 @@ public class TestHttpCookie {
.
c
(
"this is a coyote"
).
cu
(
"http://www.coyote.org"
).
dsc
(
true
)
.
d
(
".coyote.org"
).
a
(
3600
).
port
(
"80"
);
// illegal characters in set-cookie header
test
(
"Set-Cookie2:Customer=;Version#=\"1\";Path=&\"/acme\""
)
.
nil
();
// empty set-cookie string
test
(
""
).
nil
();
...
...
@@ -311,6 +307,9 @@ public class TestHttpCookie {
test
(
"Set-Cookie2:C1=\"V1\";Domain=\".sun1.com\";path=\"/www1\";Max-Age=\"100\",C2=\"V2\";Domain=\".sun2.com\";path=\"/www2\";Max-Age=\"200\""
)
.
n
(
0
,
"C1"
).
v
(
0
,
"V1"
).
p
(
0
,
"/www1"
).
a
(
0
,
100
).
d
(
0
,
".sun1.com"
)
.
n
(
1
,
"C2"
).
v
(
1
,
"V2"
).
p
(
1
,
"/www2"
).
a
(
1
,
200
).
d
(
1
,
".sun2.com"
);
// Bug 6790677: Should ignore bogus attributes
test
(
"Set-Cookie2:C1=\"V1\";foobar"
).
n
(
0
,
"C1"
).
v
(
0
,
"V1"
);
}
static
void
netscape
()
{
...
...
test/java/net/URLClassLoader/closetest/CloseTest.java
0 → 100644
浏览文件 @
a7cb2d41
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 4167874
* @library ../../../../com/sun/net/httpserver
* @build FileServerHandler
* @run shell build.sh
* @run main/othervm CloseTest
* @summary URL-downloaded jar files can consume all available file descriptors
*/
import
java.io.*
;
import
java.net.*
;
import
java.lang.reflect.*
;
import
java.util.concurrent.*
;
import
com.sun.net.httpserver.*
;
public
class
CloseTest
{
static
void
copyFile
(
String
src
,
String
dst
)
{
copyFile
(
new
File
(
src
),
new
File
(
dst
));
}
static
void
copyDir
(
String
src
,
String
dst
)
{
copyDir
(
new
File
(
src
),
new
File
(
dst
));
}
static
void
copyFile
(
File
src
,
File
dst
)
{
try
{
if
(!
src
.
isFile
())
{
throw
new
RuntimeException
(
"File not found: "
+
src
.
toString
());
}
dst
.
delete
();
dst
.
createNewFile
();
FileInputStream
i
=
new
FileInputStream
(
src
);
FileOutputStream
o
=
new
FileOutputStream
(
dst
);
byte
[]
buf
=
new
byte
[
1024
];
int
count
;
while
((
count
=
i
.
read
(
buf
))
>=
0
)
{
o
.
write
(
buf
,
0
,
count
);
}
i
.
close
();
o
.
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
static
void
rm_minus_rf
(
File
path
)
{
if
(!
path
.
exists
())
{
return
;
}
if
(
path
.
isFile
())
{
if
(!
path
.
delete
())
{
throw
new
RuntimeException
(
"Could not delete "
+
path
);
}
}
else
if
(
path
.
isDirectory
())
{
String
[]
names
=
path
.
list
();
File
[]
files
=
path
.
listFiles
();
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
rm_minus_rf
(
new
File
(
path
,
names
[
i
]));
}
if
(!
path
.
delete
())
{
throw
new
RuntimeException
(
"Could not delete "
+
path
);
}
}
else
{
throw
new
RuntimeException
(
"Trying to delete something that isn't a file or a directory"
);
}
}
static
void
copyDir
(
File
src
,
File
dst
)
{
if
(!
src
.
isDirectory
())
{
throw
new
RuntimeException
(
"Dir not found: "
+
src
.
toString
());
}
if
(
dst
.
exists
())
{
throw
new
RuntimeException
(
"Dir exists: "
+
dst
.
toString
());
}
dst
.
mkdir
();
String
[]
names
=
src
.
list
();
File
[]
files
=
src
.
listFiles
();
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
String
f
=
names
[
i
];
if
(
files
[
i
].
isDirectory
())
{
copyDir
(
files
[
i
],
new
File
(
dst
,
f
));
}
else
{
copyFile
(
new
File
(
src
,
f
),
new
File
(
dst
,
f
));
}
assert
false
;
}
}
/* expect is true if you expect to find it, false if you expect not to */
static
Class
loadClass
(
String
name
,
URLClassLoader
loader
,
boolean
expect
){
try
{
Class
clazz
=
Class
.
forName
(
name
,
true
,
loader
);
if
(!
expect
)
{
throw
new
RuntimeException
(
"loadClass: "
+
name
+
" unexpected"
);
}
return
clazz
;
}
catch
(
ClassNotFoundException
e
)
{
if
(
expect
)
{
throw
new
RuntimeException
(
"loadClass: "
+
name
+
" not found"
);
}
}
return
null
;
}
//
// needs two jar files test1.jar and test2.jar with following structure
//
// com/foo/TestClass
// com/foo/TestClass1
// com/foo/Resource1
// com/foo/Resource2
//
// and a directory hierarchy with the same structure/contents
public
static
void
main
(
String
args
[])
throws
Exception
{
String
workdir
=
System
.
getProperty
(
"test.classes"
);
if
(
workdir
==
null
)
{
workdir
=
args
[
0
];
}
if
(!
workdir
.
endsWith
(
"/"
))
{
workdir
=
workdir
+
"/"
;
}
startHttpServer
(
workdir
+
"serverRoot/"
);
String
testjar
=
workdir
+
"test.jar"
;
copyFile
(
workdir
+
"test1.jar"
,
testjar
);
test
(
testjar
,
1
);
// repeat test with different implementation
// of test.jar (whose TestClass.getValue() returns 2
copyFile
(
workdir
+
"test2.jar"
,
testjar
);
test
(
testjar
,
2
);
// repeat test using a directory of files
String
testdir
=
workdir
+
"testdir/"
;
rm_minus_rf
(
new
File
(
testdir
));
copyDir
(
workdir
+
"test1/"
,
testdir
);
test
(
testdir
,
1
);
testdir
=
workdir
+
"testdir/"
;
rm_minus_rf
(
new
File
(
testdir
));
copyDir
(
workdir
+
"test2/"
,
testdir
);
test
(
testdir
,
2
);
getHttpServer
().
stop
(
3
);
}
// create a loader on jarfile (or directory), plus a http loader
// load a class , then look for a resource
// also load a class from http loader
// then close the loader
// check further new classes/resources cannot be loaded
// check jar (or dir) can be deleted
// check existing classes can be loaded
// check boot classes can be loaded
static
void
test
(
String
name
,
int
expectedValue
)
throws
Exception
{
URL
url
=
new
URL
(
"file"
,
null
,
name
);
URL
url2
=
getServerURL
();
System
.
out
.
println
(
"Doing tests with URL: "
+
url
+
" and "
+
url2
);
URL
[]
urls
=
new
URL
[
2
];
urls
[
0
]
=
url
;
urls
[
1
]
=
url2
;
URLClassLoader
loader
=
new
URLClassLoader
(
urls
);
Class
testclass
=
loadClass
(
"com.foo.TestClass"
,
loader
,
true
);
Class
class2
=
loadClass
(
"Test"
,
loader
,
true
);
// from http
class2
.
newInstance
();
Object
test
=
testclass
.
newInstance
();
Method
method
=
testclass
.
getDeclaredMethods
()[
0
];
// int getValue();
int
res
=
(
Integer
)
method
.
invoke
(
test
);
if
(
res
!=
expectedValue
)
{
throw
new
RuntimeException
(
"wrong value from getValue() ["
+
res
+
"/"
+
expectedValue
+
"]"
);
}
// should find /resource1
URL
u1
=
loader
.
findResource
(
"com/foo/Resource1"
);
if
(
u1
==
null
)
{
throw
new
RuntimeException
(
"can't find com/foo/Resource1 in test1.jar"
);
}
loader
.
close
();
// should NOT find /resource2 even though it is in jar
URL
u2
=
loader
.
findResource
(
"com/foo/Resource2"
);
if
(
u2
!=
null
)
{
throw
new
RuntimeException
(
"com/foo/Resource2 unexpected in test1.jar"
);
}
// load tests
loadClass
(
"com.foo.TestClass1"
,
loader
,
false
);
loadClass
(
"com.foo.TestClass"
,
loader
,
true
);
loadClass
(
"java.awt.Button"
,
loader
,
true
);
// now check we can delete the path
rm_minus_rf
(
new
File
(
name
));
System
.
out
.
println
(
" ... OK"
);
}
static
HttpServer
httpServer
;
static
HttpServer
getHttpServer
()
{
return
httpServer
;
}
static
URL
getServerURL
()
throws
Exception
{
int
port
=
httpServer
.
getAddress
().
getPort
();
String
s
=
"http://127.0.0.1:"
+
port
+
"/"
;
return
new
URL
(
s
);
}
static
void
startHttpServer
(
String
docroot
)
throws
Exception
{
httpServer
=
HttpServer
.
create
(
new
InetSocketAddress
(
0
),
10
);
HttpContext
ctx
=
httpServer
.
createContext
(
"/"
,
new
FileServerHandler
(
docroot
)
);
httpServer
.
start
();
}
}
test/java/net/URLClassLoader/closetest/README
0 → 100644
浏览文件 @
a7cb2d41
test1 and test2 contain two different implementations of the same
classes. They are compiled and placed into two different target directories
and two jar files test1.jar and test2.jar.
The same class is in both jars/directories, but returns a different result
from the TestClass.getValue() method. The test does the following
1. copy test1.jar to a working directory and call it test.jar
2. load class and invoke method (checking result)
3. close the loader
4. delete test.jar (check delete succeeds)
5. copy test2.jar to same dir and repeat the test
6. The two tests are then repeated by copying the directories
test1 and test2.
The loader also includes a http:// URL in its search path and a http
server is used to serve the required class.
serverRoot is used as the root directory for the http server.
test/java/net/URLClassLoader/closetest/build.sh
0 → 100644
浏览文件 @
a7cb2d41
#!/bin/sh
#
# Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
#
#
# This script builds the test files for the test
# but not the actual test sources themselves.
#
if
[
"
${
TESTSRC
}
"
=
""
]
then
echo
"TESTSRC not set. Test cannot execute. Failed."
exit
1
fi
echo
"TESTSRC=
${
TESTSRC
}
"
if
[
"
${
TESTJAVA
}
"
=
""
]
then
echo
"TESTJAVA not set. Test cannot execute. Failed."
exit
1
fi
echo
"TESTJAVA=
${
TESTJAVA
}
"
if
[
"
${
TESTCLASSES
}
"
=
""
]
then
echo
"TESTCLASSES not set. Test cannot execute. Failed."
exit
1
fi
JAVAC
=
"
${
TESTJAVA
}
/bin/javac"
JAR
=
"
${
TESTJAVA
}
/bin/jar"
rm
-rf
${
TESTCLASSES
}
/test1
rm
-rf
${
TESTCLASSES
}
/test2
rm
-rf
${
TESTCLASSES
}
/serverRoot
mkdir
-p
${
TESTCLASSES
}
/test1/com/foo
mkdir
-p
${
TESTCLASSES
}
/test2/com/foo
mkdir
-p
${
TESTCLASSES
}
/serverRoot
cd
${
TESTSRC
}
/test1/com/foo
cp
*
${
TESTCLASSES
}
/test1/com/foo
cd
${
TESTCLASSES
}
/test1
${
JAVAC
}
com/foo/
*
.java
${
JAR
}
cvf ../test1.jar com/foo/
*
.class com/foo/Resource
*
cd
${
TESTSRC
}
/test2/com/foo
cp
*
${
TESTCLASSES
}
/test2/com/foo
cd
${
TESTCLASSES
}
/test2
${
JAVAC
}
com/foo/
*
.java
${
JAR
}
cvf ../test2.jar com/foo/
*
.class com/foo/Resource
*
cp
${
TESTSRC
}
/serverRoot/Test.java
${
TESTCLASSES
}
/serverRoot
cd
${
TESTCLASSES
}
/serverRoot
${
JAVAC
}
Test.java
test/java/net/URLClassLoader/closetest/serverRoot/Test.java
0 → 100644
浏览文件 @
a7cb2d41
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
public
class
Test
{
public
Test
()
{
System
.
out
.
println
(
"Test created"
);
}
}
test/java/net/URLClassLoader/closetest/test1/com/foo/Resource1
0 → 100644
浏览文件 @
a7cb2d41
Hello World
test/java/net/URLClassLoader/closetest/test1/com/foo/Resource2
0 → 100644
浏览文件 @
a7cb2d41
Hello World Again
test/java/net/URLClassLoader/closetest/test1/com/foo/TestClass.java
0 → 100644
浏览文件 @
a7cb2d41
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
com.foo
;
public
class
TestClass
{
public
int
getValue
()
{
return
1
;
}
}
/*
public class TestClass {
public int getValue () {
return 2;
}
}
*/
test/java/net/URLClassLoader/closetest/test1/com/foo/TestClass1.java
0 → 100644
浏览文件 @
a7cb2d41
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
com.foo
;
public
class
TestClass1
{}
test/java/net/URLClassLoader/closetest/test2/com/foo/Resource1
0 → 100644
浏览文件 @
a7cb2d41
Hello World
test/java/net/URLClassLoader/closetest/test2/com/foo/Resource2
0 → 100644
浏览文件 @
a7cb2d41
Hello World Again
test/java/net/URLClassLoader/closetest/test2/com/foo/TestClass.java
0 → 100644
浏览文件 @
a7cb2d41
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
com.foo
;
/*
public class TestClass {
public int getValue () {
return 1;
}
}
*/
public
class
TestClass
{
public
int
getValue
()
{
return
2
;
}
}
test/java/net/URLClassLoader/closetest/test2/com/foo/TestClass1.java
0 → 100644
浏览文件 @
a7cb2d41
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package
com.foo
;
public
class
TestClass1
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录