--- a/jdk/make/common/Release.gmk Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/make/common/Release.gmk Mon Mar 07 14:48:27 2011 -0800
@@ -62,7 +62,8 @@
# This is an interim solution until the ct.sym is replaced
# with a new module system (being discussed for JDK 7).
#
-EXPORTED_PRIVATE_PKGS = com.sun.servicetag
+EXPORTED_PRIVATE_PKGS = com.sun.servicetag \
+ com.oracle.net
# 64-bit solaris has a few special cases. We define the variable
# SOLARIS64 for use in this Makefile to easily test those cases
--- a/jdk/make/common/shared/Defs-java.gmk Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/make/common/shared/Defs-java.gmk Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2007, 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
@@ -45,7 +45,7 @@
JAVA_MEM_FLAGS += -Xms$(MIN_VM_MEMORY)m -XX:PermSize=32m -XX:MaxPermSize=160m
endif
-#
+#
# All java tools (javac, javah, and javadoc) run faster with certain java
# options, this macro should be used with all these tools.
# In particular, the client VM makes these tools run faster when
@@ -122,6 +122,17 @@
JAVACFLAGS += -Werror
endif
+#
+# Some licensees do not get the Security Source bundles. We will
+# fall back on the prebuilt jce.jar so that we can do a best
+# attempt at building. If sources exist, we always want to
+# build/use the most recent source instead of an older jce.jar, whether
+# built implicitly/explicitly.
+#
+ifeq ($(wildcard $(SHARE_SRC)/classes/javax/crypto/Cipher.java),)
+ JCEFLAGS = $(CLASSPATH_SEPARATOR)$(LIBDIR)/jce.jar
+endif
+
# Add the source level
SOURCE_LANGUAGE_VERSION = 7
LANGUAGE_VERSION = -source $(SOURCE_LANGUAGE_VERSION)
@@ -132,11 +143,11 @@
CLASS_VERSION = -target $(TARGET_CLASS_VERSION)
JAVACFLAGS += $(CLASS_VERSION)
JAVACFLAGS += -encoding ascii
-JAVACFLAGS += "-Xbootclasspath:$(CLASSBINDIR)"
+JAVACFLAGS += "-Xbootclasspath:$(CLASSBINDIR)$(JCEFLAGS)"
JAVACFLAGS += $(OTHER_JAVACFLAGS)
# Needed for javah
-JAVAHFLAGS += -bootclasspath $(CLASSBINDIR)
+JAVAHFLAGS += -bootclasspath "$(CLASSBINDIR)$(JCEFLAGS)"
# Needed for javadoc to ensure it builds documentation
# against the newly built classes
--- a/jdk/make/docs/NON_CORE_PKGS.gmk Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/make/docs/NON_CORE_PKGS.gmk Mon Mar 07 14:48:27 2011 -0800
@@ -91,8 +91,6 @@
TRACING_PKGS = com.sun.tracing \
com.sun.tracing.dtrace
-ORACLENET_PKGS = com.oracle.net
-
# non-core packages in rt.jar
NON_CORE_PKGS = $(DOMAPI_PKGS) \
$(MGMT_PKGS) \
@@ -103,6 +101,5 @@
$(HTTPSERVER_PKGS) \
$(SMARTCARDIO_PKGS) \
$(TRACING_PKGS) \
- $(SCTPAPI_PKGS) \
- $(ORACLENET_PKGS)
+ $(SCTPAPI_PKGS)
--- a/jdk/make/java/java/FILES_java.gmk Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/make/java/java/FILES_java.gmk Mon Mar 07 14:48:27 2011 -0800
@@ -466,7 +466,6 @@
java/security/ProtectionDomain.java \
java/net/URLClassLoader.java \
java/net/URLConnection.java \
- sun/misc/BootClassLoaderHook.java \
sun/misc/Launcher.java \
sun/misc/MetaIndex.java \
sun/misc/URLClassPath.java \
--- a/jdk/src/share/classes/com/sun/jarsigner/ContentSignerParameters.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/com/sun/jarsigner/ContentSignerParameters.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -26,9 +26,7 @@
package com.sun.jarsigner;
import java.net.URI;
-import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
-import java.util.Set;
import java.util.zip.ZipFile;
/**
@@ -83,13 +81,6 @@
public X509Certificate[] getSignerCertificateChain();
/**
- * Retrieves the signer's X.509 CRLs.
- *
- * @return An unmodifiable set of X.509 CRLs (never <code>null</code>)
- */
- public Set<X509CRL> getCRLs();
-
- /**
* Retrieves the content that was signed.
* The content is the JAR file's signature file.
*
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -1011,7 +1011,7 @@
return -1;
}
- Comparator<Entry> entryOutputOrder = new Comparator<>() {
+ Comparator<Entry> entryOutputOrder = new Comparator<Entry>() {
public int compare(Entry e0, Entry e1) {
int k0 = getOutputIndex(e0);
int k1 = getOutputIndex(e1);
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -785,7 +785,7 @@
defMap.entrySet().toArray(layoutsAndCounts);
// Sort by count, most frequent first.
// Predefs. participate in this sort, though it does not matter.
- Arrays.sort(layoutsAndCounts, new Comparator<>() {
+ Arrays.sort(layoutsAndCounts, new Comparator<Object>() {
public int compare(Object o0, Object o1) {
Map.Entry e0 = (Map.Entry) o0;
Map.Entry e1 = (Map.Entry) o1;
--- a/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -380,13 +380,19 @@
}
LdapRequest writeRequest(BerEncoder ber, int msgId) throws IOException {
- return writeRequest(ber, msgId, false /* pauseAfterReceipt */);
+ return writeRequest(ber, msgId, false /* pauseAfterReceipt */, -1);
}
- LdapRequest writeRequest(BerEncoder ber, int msgId, boolean pauseAfterReceipt)
- throws IOException {
+ LdapRequest writeRequest(BerEncoder ber, int msgId,
+ boolean pauseAfterReceipt) throws IOException {
+ return writeRequest(ber, msgId, pauseAfterReceipt, -1);
+ }
- LdapRequest req = new LdapRequest(msgId, pauseAfterReceipt);
+ LdapRequest writeRequest(BerEncoder ber, int msgId,
+ boolean pauseAfterReceipt, int replyQueueCapacity) throws IOException {
+
+ LdapRequest req =
+ new LdapRequest(msgId, pauseAfterReceipt, replyQueueCapacity);
addRequest(req);
if (traceFile != null) {
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -516,7 +516,8 @@
LdapResult search(String dn, int scope, int deref, int sizeLimit,
int timeLimit, boolean attrsOnly, String attrs[],
String filter, int batchSize, Control[] reqCtls,
- Hashtable binaryAttrs, boolean waitFirstReply)
+ Hashtable binaryAttrs, boolean waitFirstReply,
+ int replyQueueCapacity)
throws IOException, NamingException {
ensureOpen();
@@ -543,7 +544,8 @@
if (isLdapv3) encodeControls(ber, reqCtls);
ber.endSeq();
- LdapRequest req = conn.writeRequest(ber, curMsgId);
+ LdapRequest req =
+ conn.writeRequest(ber, curMsgId, false, replyQueueCapacity);
res.msgId = curMsgId;
res.status = LdapClient.LDAP_SUCCESS; //optimistic
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -191,6 +191,14 @@
// Environment property for the domain name (derived from this context's DN)
private static final String DOMAIN_NAME = "com.sun.jndi.ldap.domainname";
+ // Block until the first search reply is received
+ private static final String WAIT_FOR_REPLY =
+ "com.sun.jndi.ldap.search.waitForReply";
+
+ // Size of the queue of unprocessed search replies
+ private static final String REPLY_QUEUE_SIZE =
+ "com.sun.jndi.ldap.search.replyQueueSize";
+
// ----------------- Fields that don't change -----------------------
private static final NameParser parser = new LdapNameParser();
@@ -246,6 +254,8 @@
private Hashtable binaryAttrs = null; // attr values returned as byte[]
private int connectTimeout = -1; // no timeout value
private int readTimeout = -1; // no timeout value
+ private boolean waitForReply = true; // wait for search response
+ private int replyQueueSize = -1; // unlimited queue size
private boolean useSsl = false; // true if SSL protocol is active
private boolean useDefaultPortNumber = false; // no port number was supplied
@@ -1759,8 +1769,8 @@
SearchControls cons,
Continuation cont)
throws NamingException {
- return searchAux(name, filter, cloneSearchControls(cons), true, true,
- cont);
+ return searchAux(name, filter, cloneSearchControls(cons), true,
+ waitForReply, cont);
}
protected NamingEnumeration c_search(Name name,
@@ -1928,7 +1938,7 @@
}
private LdapResult doSearch(Name name, String filter, SearchControls cons,
- boolean relative, boolean waitFirstReply) throws NamingException {
+ boolean relative, boolean waitForReply) throws NamingException {
ensureOpen();
try {
int scope;
@@ -1984,7 +1994,8 @@
batchSize,
reqCtls,
binaryAttrs,
- waitFirstReply);
+ waitForReply,
+ replyQueueSize);
respCtls = answer.resControls; // retrieve response controls
return answer;
@@ -2170,6 +2181,10 @@
connectTimeout = -1;
} else if (propName.equals(READ_TIMEOUT)) {
readTimeout = -1;
+ } else if (propName.equals(WAIT_FOR_REPLY)) {
+ waitForReply = true;
+ } else if (propName.equals(REPLY_QUEUE_SIZE)) {
+ replyQueueSize = -1;
// The following properties affect the connection
@@ -2225,6 +2240,11 @@
setConnectTimeout((String)propVal);
} else if (propName.equals(READ_TIMEOUT)) {
setReadTimeout((String)propVal);
+ } else if (propName.equals(WAIT_FOR_REPLY)) {
+ setWaitForReply((String)propVal);
+ } else if (propName.equals(REPLY_QUEUE_SIZE)) {
+ setReplyQueueSize((String)propVal);
+
// The following properties affect the connection
} else if (propName.equals(Context.SECURITY_PROTOCOL)) {
@@ -2312,6 +2332,13 @@
// Set the read timeout
setReadTimeout((String)envprops.get(READ_TIMEOUT));
+ // Set the flag that controls whether to block until the first reply
+ // is received
+ setWaitForReply((String)envprops.get(WAIT_FOR_REPLY));
+
+ // Set the size of the queue of unprocessed search replies
+ setReplyQueueSize((String)envprops.get(REPLY_QUEUE_SIZE));
+
// When connection is created, it will use these and other
// properties from the environment
}
@@ -2442,6 +2469,34 @@
}
/**
+ * Sets the size of the queue of unprocessed search replies
+ */
+ private void setReplyQueueSize(String replyQueueSizeProp) {
+ if (replyQueueSizeProp != null) {
+ replyQueueSize = Integer.parseInt(replyQueueSizeProp);
+ // disallow an empty queue
+ if (replyQueueSize <= 0) {
+ replyQueueSize = -1; // unlimited
+ }
+ } else {
+ replyQueueSize = -1; // unlimited
+ }
+ }
+
+ /**
+ * Sets the flag that controls whether to block until the first search
+ * reply is received
+ */
+ private void setWaitForReply(String waitForReplyProp) {
+ if (waitForReplyProp != null &&
+ (waitForReplyProp.equalsIgnoreCase("false"))) {
+ waitForReply = false;
+ } else {
+ waitForReply = true;
+ }
+ }
+
+ /**
* Sets the read timeout value
*/
private void setReadTimeout(String readTimeoutProp) {
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapRequest.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapRequest.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -26,7 +26,8 @@
package com.sun.jndi.ldap;
import java.io.IOException;
-import java.util.Vector;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
import javax.naming.CommunicationException;
final class LdapRequest {
@@ -35,14 +36,26 @@
int msgId; // read-only
private int gotten = 0;
- private Vector replies = new Vector(3);
+ private BlockingQueue<BerDecoder> replies;
+ private int highWatermark = -1;
private boolean cancelled = false;
private boolean pauseAfterReceipt = false;
private boolean completed = false;
LdapRequest(int msgId, boolean pause) {
+ this(msgId, pause, -1);
+ }
+
+ LdapRequest(int msgId, boolean pause, int replyQueueCapacity) {
this.msgId = msgId;
this.pauseAfterReceipt = pause;
+ if (replyQueueCapacity == -1) {
+ this.replies = new LinkedBlockingQueue<BerDecoder>();
+ } else {
+ this.replies =
+ new LinkedBlockingQueue<BerDecoder>(replyQueueCapacity);
+ highWatermark = (replyQueueCapacity * 80) / 100; // 80% capacity
+ }
}
synchronized void cancel() {
@@ -57,7 +70,13 @@
if (cancelled) {
return false;
}
- replies.addElement(ber);
+
+ // Add a new reply to the queue of unprocessed replies.
+ try {
+ replies.put(ber);
+ } catch (InterruptedException e) {
+ // ignore
+ }
// peek at the BER buffer to check if it is a SearchResultDone PDU
try {
@@ -70,6 +89,14 @@
ber.reset();
notify(); // notify anyone waiting for reply
+ /*
+ * If a queue capacity has been set then trigger a pause when the
+ * queue has filled to 80% capacity. Later, when the queue has drained
+ * then the reader gets unpaused.
+ */
+ if (highWatermark != -1 && replies.size() >= highWatermark) {
+ return true; // trigger the pause
+ }
return pauseAfterReceipt;
}
@@ -79,14 +106,12 @@
" cancelled");
}
- if (gotten < replies.size()) {
- BerDecoder answer = (BerDecoder)replies.elementAt(gotten);
- replies.setElementAt(null, gotten); // remove reference
- ++gotten; // skip to next
- return answer;
- } else {
- return null;
- }
+ /*
+ * Remove a reply if the queue is not empty.
+ * poll returns null if queue is empty.
+ */
+ BerDecoder reply = replies.poll();
+ return reply;
}
synchronized boolean hasSearchCompleted() {
--- a/jdk/src/share/classes/java/awt/color/ICC_Profile.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/awt/color/ICC_Profile.java Mon Mar 07 14:48:27 2011 -0800
@@ -58,7 +58,6 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
-import sun.misc.BootClassLoaderHook;
/**
* A representation of color profile data for device independent and
@@ -865,8 +864,7 @@
case ColorSpace.CS_PYCC:
synchronized(ICC_Profile.class) {
if (PYCCprofile == null) {
- if (BootClassLoaderHook.getHook() != null ||
- standardProfileExists("PYCC.pf"))
+ if (standardProfileExists("PYCC.pf"))
{
ProfileDeferralInfo pInfo =
new ProfileDeferralInfo("PYCC.pf",
--- a/jdk/src/share/classes/java/io/File.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/io/File.java Mon Mar 07 14:48:27 2011 -0800
@@ -2055,7 +2055,7 @@
*
* @return a {@code Path} constructed from this abstract path
*
- * @throws InvalidPathException
+ * @throws java.nio.file.InvalidPathException
* if a {@code Path} object cannot be constructed from the abstract
* path (see {@link java.nio.file.FileSystem#getPath FileSystem.getPath})
*
--- a/jdk/src/share/classes/java/lang/ClassLoader.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/lang/ClassLoader.java Mon Mar 07 14:48:27 2011 -0800
@@ -51,7 +51,6 @@
import java.util.Hashtable;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
-import sun.misc.BootClassLoaderHook;
import sun.misc.ClassFileTransformer;
import sun.misc.CompoundEnumeration;
import sun.misc.Resource;
@@ -1300,7 +1299,6 @@
* Find resources from the VM's built-in classloader.
*/
private static URL getBootstrapResource(String name) {
- BootClassLoaderHook.preLoadResource(name);
URLClassPath ucp = getBootstrapClassPath();
Resource res = ucp.getResource(name);
return res != null ? res.getURL() : null;
@@ -1814,7 +1812,6 @@
// Invoked in the java.lang.Runtime class to implement load and loadLibrary.
static void loadLibrary(Class fromClass, String name,
boolean isAbsolute) {
- BootClassLoaderHook.preLoadLibrary(name);
ClassLoader loader =
(fromClass == null) ? null : fromClass.getClassLoader();
if (sys_paths == null) {
--- a/jdk/src/share/classes/java/lang/Package.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Package.java Mon Mar 07 14:48:27 2011 -0800
@@ -576,12 +576,10 @@
* Returns the Manifest for the specified JAR file name.
*/
private static Manifest loadManifest(String fn) {
- try {
- FileInputStream fis = new FileInputStream(fn);
- JarInputStream jis = new JarInputStream(fis, false);
- Manifest man = jis.getManifest();
- jis.close();
- return man;
+ try (FileInputStream fis = new FileInputStream(fn);
+ JarInputStream jis = new JarInputStream(fis, false))
+ {
+ return jis.getManifest();
} catch (IOException e) {
return null;
}
--- a/jdk/src/share/classes/java/net/HttpURLConnection.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/net/HttpURLConnection.java Mon Mar 07 14:48:27 2011 -0800
@@ -400,7 +400,8 @@
* @exception ProtocolException if the method cannot be reset or if
* the requested method isn't valid for HTTP.
* @exception SecurityException if a security manager is set and the
- * "allowHttpTrace" NetPermission is not granted.
+ * method is "TRACE", but the "allowHttpTrace"
+ * NetPermission is not granted.
* @see #getRequestMethod()
*/
public void setRequestMethod(String method) throws ProtocolException {
--- a/jdk/src/share/classes/java/net/NetPermission.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/net/NetPermission.java Mon Mar 07 14:48:27 2011 -0800
@@ -73,6 +73,13 @@
* </tr>
*
* <tr>
+ * <td>getNetworkInformation</td>
+ * <td>The ability to retrieve all information about local network interfaces.</td>
+ * <td>Malicious code can read information about network hardware such as
+ * MAC addresses, which could be used to construct local IPv6 addresses.</td>
+ * </tr>
+ *
+ * <tr>
* <td>getProxySelector</td>
* <td>The ability to get the proxy selector used to make decisions
* on which proxies to use when making network connections.</td>
--- a/jdk/src/share/classes/java/net/URI.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/net/URI.java Mon Mar 07 14:48:27 2011 -0800
@@ -991,7 +991,7 @@
* authority and path are taken from the given URI. </p></li>
*
* <li><p> Otherwise the new URI's authority component is copied from
- * this URI, and its path is computed as follows: </p></li>
+ * this URI, and its path is computed as follows: </p>
*
* <ol type=a>
*
@@ -1005,7 +1005,7 @@
* path and then normalizing the result as if by invoking the {@link
* #normalize() normalize} method. </p></li>
*
- * </ol>
+ * </ol></li>
*
* </ol>
*
@@ -1511,7 +1511,7 @@
* fragments. </p></li>
*
* <li><p> Two hierarchical URIs with identical schemes are ordered
- * according to the ordering of their authority components: </p></li>
+ * according to the ordering of their authority components: </p>
*
* <ul type=disc>
*
@@ -1526,7 +1526,7 @@
* the URIs are ordered according to the ordering of their authority
* components. </p></li>
*
- * </ul>
+ * </ul></li>
*
* <li><p> Finally, two hierarchical URIs with identical schemes and
* authority components are ordered according to the ordering of their
--- a/jdk/src/share/classes/java/net/package.html Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/net/package.html Mon Mar 07 14:48:27 2011 -0800
@@ -31,18 +31,18 @@
<p> The java.net package can be roughly divided in two sections:</p>
<ul>
- <li> <p><i>A Low Level API</i>, which deals with the following abstractions:</p></li>
+ <li> <p><i>A Low Level API</i>, which deals with the following abstractions:</p>
<ul>
<li><p><i>Addresses</i>, which are networking identifiers, like IP addresses.</p></li>
<li><p><i>Sockets</i>, which are basic bidirectional data communication mechanisms.</p></li>
<li><p><i>Interfaces</i>, which describe network interfaces. </p></li>
- </ul>
- <li> <p><i>A High Level API</i>, which deals with the following abstractions:</p></li>
+ </ul></li>
+ <li> <p><i>A High Level API</i>, which deals with the following abstractions:</p>
<ul>
<li><p><i>URIs</i>, which represent Universal Resource Identifiers.</p></li>
<li><p><i>URLs</i>, which represent Universal Resource Locators.</p></li>
<li><p><i>Connections</i>, which represents connections to the resource pointed to by <i>URLs</i>.</p></li>
- </ul>
+ </ul></li>
</ul>
<h2>Addresses</h2>
<p>Addresses are used throughout the java.net APIs as either host identifiers, or socket endpoint identifiers.</p>
--- a/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java Mon Mar 07 14:48:27 2011 -0800
@@ -48,12 +48,12 @@
*
* <p> An asynchronous file channel does not have a <i>current position</i>
* within the file. Instead, the file position is specified to each read and
- * write methd that initiate asynchronous operations. A {@link CompletionHandler}
+ * write method that initiates asynchronous operations. A {@link CompletionHandler}
* is specified as a parameter and is invoked to consume the result of the I/O
* operation. This class also defines read and write methods that initiate
* asynchronous operations, returning a {@link Future} to represent the pending
* result of the operation. The {@code Future} may be used to check if the
- * operation has completed, to wait for its completion.
+ * operation has completed, wait for its completion, and retrieve the result.
*
* <p> In addition to read and write operations, this class defines the
* following operations: </p>
@@ -73,13 +73,13 @@
* which tasks are submitted to handle I/O events and dispatch to completion
* handlers that consume the results of I/O operations on the channel. The
* completion handler for an I/O operation initiated on a channel is guaranteed
- * to be invoked by one threads in the thread pool (This ensures that the
+ * to be invoked by one of the threads in the thread pool (This ensures that the
* completion handler is run by a thread with the expected <em>identity</em>).
* Where an I/O operation completes immediately, and the initiating thread is
* itself a thread in the thread pool, then the completion handler may be invoked
* directly by the initiating thread. When an {@code AsynchronousFileChannel} is
* created without specifying a thread pool then the channel is associated with
- * a system-dependent and default thread pool that may be shared with other
+ * a system-dependent default thread pool that may be shared with other
* channels. The default thread pool is configured by the system properties
* defined by the {@link AsynchronousChannelGroup} class.
*
--- a/jdk/src/share/classes/java/nio/channels/SocketChannel.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/nio/channels/SocketChannel.java Mon Mar 07 14:48:27 2011 -0800
@@ -182,10 +182,13 @@
SocketChannel sc = open();
try {
sc.connect(remote);
- } finally {
- if (!sc.isConnected()) {
- try { sc.close(); } catch (IOException x) { }
+ } catch (Throwable x) {
+ try {
+ sc.close();
+ } catch (Throwable suppressed) {
+ x.addSuppressed(suppressed);
}
+ throw x;
}
assert sc.isConnected();
return sc;
--- a/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java Mon Mar 07 14:48:27 2011 -0800
@@ -135,11 +135,13 @@
view.setTimes(attrs.lastModifiedTime(),
attrs.lastAccessTime(),
attrs.creationTime());
- } catch (IOException x) {
+ } catch (Throwable x) {
// rollback
try {
Files.delete(target);
- } catch (IOException ignore) { }
+ } catch (Throwable suppressed) {
+ x.addSuppressed(suppressed);
+ }
throw x;
}
}
--- a/jdk/src/share/classes/java/nio/file/Files.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/nio/file/Files.java Mon Mar 07 14:48:27 2011 -0800
@@ -129,17 +129,18 @@
* <pre>
* Path path = ...
*
- * // replace an existing file or create the file if it doesn't initially exist
+ * // truncate and overwrite an existing file, or create the file if
+ * // it doesn't initially exist
* OutputStream out = Files.newOutputStream(path);
*
* // append to an existing file, fail if the file does not exist
* out = Files.newOutputStream(path, APPEND);
*
* // append to an existing file, create file if it doesn't initially exist
- * out = Files.newOutputStream(CREATE, APPEND);
+ * out = Files.newOutputStream(path, CREATE, APPEND);
*
* // always create new file, failing if it already exists
- * out = Files.newOutputStream(CREATE_NEW);
+ * out = Files.newOutputStream(path, CREATE_NEW);
* </pre>
*
* @param path
@@ -793,7 +794,8 @@
FileAttribute<?>... attrs)
throws IOException
{
- return TempFileHelper.createTempFile(dir, prefix, suffix, attrs);
+ return TempFileHelper.createTempFile(Objects.requireNonNull(dir),
+ prefix, suffix, attrs);
}
/**
@@ -890,13 +892,14 @@
FileAttribute<?>... attrs)
throws IOException
{
- return TempFileHelper.createTempDirectory(dir, prefix, attrs);
+ return TempFileHelper.createTempDirectory(Objects.requireNonNull(dir),
+ prefix, attrs);
}
/**
* Creates a new directory in the default temporary-file directory, using
- * the given prefix and suffix to generate its name. The resulting {@code
- * Path} is associated with the default {@code FileSystem}.
+ * the given prefix to generate its name. The resulting {@code Path} is
+ * associated with the default {@code FileSystem}.
*
* <p> This method works in exactly the manner specified by {@link
* #createTempDirectory(Path,String,FileAttribute[])} method for the case
@@ -2583,7 +2586,7 @@
* walkFileTree(start, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor)
* </pre></blockquote>
* In other words, it does not follow symbolic links, and visits all levels
- * of the file level.
+ * of the file tree.
*
* @param start
* the starting file
@@ -3005,7 +3008,7 @@
* or after some bytes have been written to the file.
*
* <p> <b>Usage example</b>: By default the method creates a new file or
- * overrides an existing file. Suppose you instead want to append bytes
+ * overwrites an existing file. Suppose you instead want to append bytes
* to an existing file:
* <pre>
* Path path = ...
--- a/jdk/src/share/classes/java/security/CodeSigner.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/security/CodeSigner.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -26,10 +26,7 @@
package java.security;
import java.io.*;
-import java.security.cert.CRL;
import java.security.cert.CertPath;
-import sun.misc.JavaSecurityCodeSignerAccess;
-import sun.misc.SharedSecrets;
/**
* This class encapsulates information about a code signer.
@@ -167,44 +164,6 @@
return sb.toString();
}
- // A private attribute attached to this CodeSigner object. Can be accessed
- // through SharedSecrets.getJavaSecurityCodeSignerAccess().[g|s]etCRLs
- //
- // Currently called in SignatureFileVerifier.getSigners
- private transient CRL[] crls;
-
- /**
- * Sets the CRLs attached
- * @param crls, null to clear
- */
- void setCRLs(CRL[] crls) {
- this.crls = crls;
- }
-
- /**
- * Returns the CRLs attached
- * @return the crls, initially null
- */
- CRL[] getCRLs() {
- return crls;
- }
-
- // Set up JavaSecurityCodeSignerAccess in SharedSecrets
- static {
- SharedSecrets.setJavaSecurityCodeSignerAccess(
- new JavaSecurityCodeSignerAccess() {
- @Override
- public void setCRLs(CodeSigner signer, CRL[] crls) {
- signer.setCRLs(crls);
- }
-
- @Override
- public CRL[] getCRLs(CodeSigner signer) {
- return signer.getCRLs();
- }
- });
- }
-
// Explicitly reset hash code value to -1
private void readObject(ObjectInputStream ois)
throws IOException, ClassNotFoundException {
--- a/jdk/src/share/classes/java/util/Currency.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/Currency.java Mon Mar 07 14:48:27 2011 -0800
@@ -233,7 +233,9 @@
"currency.properties");
if (propFile.exists()) {
Properties props = new Properties();
- props.load(new FileReader(propFile));
+ try (FileReader fr = new FileReader(propFile)) {
+ props.load(fr);
+ }
Set<String> keys = props.stringPropertyNames();
Pattern propertiesPattern =
Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])");
--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java Mon Mar 07 14:48:27 2011 -0800
@@ -272,13 +272,6 @@
private static final Node<Object> PREV_TERMINATOR, NEXT_TERMINATOR;
- static {
- PREV_TERMINATOR = new Node<Object>(null);
- PREV_TERMINATOR.next = PREV_TERMINATOR;
- NEXT_TERMINATOR = new Node<Object>(null);
- NEXT_TERMINATOR.prev = NEXT_TERMINATOR;
- }
-
@SuppressWarnings("unchecked")
Node<E> prevTerminator() {
return (Node<E>) PREV_TERMINATOR;
@@ -294,6 +287,9 @@
volatile E item;
volatile Node<E> next;
+ Node() { // default constructor for NEXT_TERMINATOR, PREV_TERMINATOR
+ }
+
/**
* Constructs a new node. Uses relaxed write because item can
* only be seen after publication via casNext or casPrev.
@@ -324,14 +320,25 @@
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE =
- sun.misc.Unsafe.getUnsafe();
- private static final long prevOffset =
- objectFieldOffset(UNSAFE, "prev", Node.class);
- private static final long itemOffset =
- objectFieldOffset(UNSAFE, "item", Node.class);
- private static final long nextOffset =
- objectFieldOffset(UNSAFE, "next", Node.class);
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long prevOffset;
+ private static final long itemOffset;
+ private static final long nextOffset;
+
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = Node.class;
+ prevOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("prev"));
+ itemOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("item"));
+ nextOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("next"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/**
@@ -1422,14 +1429,6 @@
initHeadTail(h, t);
}
- // Unsafe mechanics
-
- private static final sun.misc.Unsafe UNSAFE =
- sun.misc.Unsafe.getUnsafe();
- private static final long headOffset =
- objectFieldOffset(UNSAFE, "head", ConcurrentLinkedDeque.class);
- private static final long tailOffset =
- objectFieldOffset(UNSAFE, "tail", ConcurrentLinkedDeque.class);
private boolean casHead(Node<E> cmp, Node<E> val) {
return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
@@ -1439,15 +1438,25 @@
return UNSAFE.compareAndSwapObject(this, tailOffset, cmp, val);
}
- static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
- String field, Class<?> klazz) {
+ // Unsafe mechanics
+
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long headOffset;
+ private static final long tailOffset;
+ static {
+ PREV_TERMINATOR = new Node<Object>();
+ PREV_TERMINATOR.next = PREV_TERMINATOR;
+ NEXT_TERMINATOR = new Node<Object>();
+ NEXT_TERMINATOR.prev = NEXT_TERMINATOR;
try {
- return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
- } catch (NoSuchFieldException e) {
- // Convert Exception to corresponding Error
- NoSuchFieldError error = new NoSuchFieldError(field);
- error.initCause(e);
- throw error;
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = ConcurrentLinkedDeque.class;
+ headOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("head"));
+ tailOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("tail"));
+ } catch (Exception e) {
+ throw new Error(e);
}
}
}
--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java Mon Mar 07 14:48:27 2011 -0800
@@ -194,12 +194,22 @@
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE =
- sun.misc.Unsafe.getUnsafe();
- private static final long nextOffset =
- objectFieldOffset(UNSAFE, "next", Node.class);
- private static final long itemOffset =
- objectFieldOffset(UNSAFE, "item", Node.class);
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long itemOffset;
+ private static final long nextOffset;
+
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = Node.class;
+ itemOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("item"));
+ nextOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("next"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/**
@@ -790,14 +800,6 @@
throw new NullPointerException();
}
- // Unsafe mechanics
-
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long headOffset =
- objectFieldOffset(UNSAFE, "head", ConcurrentLinkedQueue.class);
- private static final long tailOffset =
- objectFieldOffset(UNSAFE, "tail", ConcurrentLinkedQueue.class);
-
private boolean casTail(Node<E> cmp, Node<E> val) {
return UNSAFE.compareAndSwapObject(this, tailOffset, cmp, val);
}
@@ -806,15 +808,21 @@
return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
}
- static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
- String field, Class<?> klazz) {
+ // Unsafe mechanics
+
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long headOffset;
+ private static final long tailOffset;
+ static {
try {
- return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
- } catch (NoSuchFieldException e) {
- // Convert Exception to corresponding Error
- NoSuchFieldError error = new NoSuchFieldError(field);
- error.initCause(e);
- throw error;
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = ConcurrentLinkedQueue.class;
+ headOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("head"));
+ tailOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("tail"));
+ } catch (Exception e) {
+ throw new Error(e);
}
}
}
--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Mon Mar 07 14:48:27 2011 -0800
@@ -507,13 +507,24 @@
return new AbstractMap.SimpleImmutableEntry<K,V>(key, v);
}
- // Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long valueOffset =
- objectFieldOffset(UNSAFE, "value", Node.class);
- private static final long nextOffset =
- objectFieldOffset(UNSAFE, "next", Node.class);
+ // UNSAFE mechanics
+
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long valueOffset;
+ private static final long nextOffset;
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = Node.class;
+ valueOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("value"));
+ nextOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("next"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/* ---------------- Indexing -------------- */
@@ -580,10 +591,18 @@
}
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long rightOffset =
- objectFieldOffset(UNSAFE, "right", Index.class);
-
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long rightOffset;
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = Index.class;
+ rightOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("right"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/* ---------------- Head nodes -------------- */
@@ -3082,20 +3101,16 @@
}
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long headOffset =
- objectFieldOffset(UNSAFE, "head", ConcurrentSkipListMap.class);
-
- static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
- String field, Class<?> klazz) {
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long headOffset;
+ static {
try {
- return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
- } catch (NoSuchFieldException e) {
- // Convert Exception to corresponding Error
- NoSuchFieldError error = new NoSuchFieldError(field);
- error.initCause(e);
- throw error;
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = ConcurrentSkipListMap.class;
+ headOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("head"));
+ } catch (Exception e) {
+ throw new Error(e);
}
}
-
}
--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentSkipListSet.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentSkipListSet.java Mon Mar 07 14:48:27 2011 -0800
@@ -470,16 +470,20 @@
}
// Support for resetting map in clone
- private static final Unsafe unsafe = Unsafe.getUnsafe();
+ private void setMap(ConcurrentNavigableMap<E,Object> map) {
+ UNSAFE.putObjectVolatile(this, mapOffset, map);
+ }
+
+ private static final sun.misc.Unsafe UNSAFE;
private static final long mapOffset;
static {
try {
- mapOffset = unsafe.objectFieldOffset
- (ConcurrentSkipListSet.class.getDeclaredField("m"));
- } catch (Exception ex) { throw new Error(ex); }
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = ConcurrentSkipListSet.class;
+ mapOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("m"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
}
- private void setMap(ConcurrentNavigableMap<E,Object> map) {
- unsafe.putObjectVolatile(this, mapOffset, map);
- }
-
}
--- a/jdk/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java Mon Mar 07 14:48:27 2011 -0800
@@ -1318,16 +1318,19 @@
}
// Support for resetting lock while deserializing
- private static final Unsafe unsafe = Unsafe.getUnsafe();
+ private void resetLock() {
+ UNSAFE.putObjectVolatile(this, lockOffset, new ReentrantLock());
+ }
+ private static final sun.misc.Unsafe UNSAFE;
private static final long lockOffset;
static {
try {
- lockOffset = unsafe.objectFieldOffset
- (CopyOnWriteArrayList.class.getDeclaredField("lock"));
- } catch (Exception ex) { throw new Error(ex); }
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = CopyOnWriteArrayList.class;
+ lockOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("lock"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
}
- private void resetLock() {
- unsafe.putObjectVolatile(this, lockOffset, new ReentrantLock());
- }
-
}
--- a/jdk/src/share/classes/java/util/concurrent/LinkedTransferQueue.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/LinkedTransferQueue.java Mon Mar 07 14:48:27 2011 -0800
@@ -525,16 +525,27 @@
return false;
}
+ private static final long serialVersionUID = -3375979862319811754L;
+
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long nextOffset =
- objectFieldOffset(UNSAFE, "next", Node.class);
- private static final long itemOffset =
- objectFieldOffset(UNSAFE, "item", Node.class);
- private static final long waiterOffset =
- objectFieldOffset(UNSAFE, "waiter", Node.class);
-
- private static final long serialVersionUID = -3375979862319811754L;
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long itemOffset;
+ private static final long nextOffset;
+ private static final long waiterOffset;
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = Node.class;
+ itemOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("item"));
+ nextOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("next"));
+ waiterOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("waiter"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/** head of the queue; null until first enqueue */
@@ -1312,23 +1323,22 @@
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long headOffset =
- objectFieldOffset(UNSAFE, "head", LinkedTransferQueue.class);
- private static final long tailOffset =
- objectFieldOffset(UNSAFE, "tail", LinkedTransferQueue.class);
- private static final long sweepVotesOffset =
- objectFieldOffset(UNSAFE, "sweepVotes", LinkedTransferQueue.class);
-
- static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
- String field, Class<?> klazz) {
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long headOffset;
+ private static final long tailOffset;
+ private static final long sweepVotesOffset;
+ static {
try {
- return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
- } catch (NoSuchFieldException e) {
- // Convert Exception to corresponding Error
- NoSuchFieldError error = new NoSuchFieldError(field);
- error.initCause(e);
- throw error;
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = LinkedTransferQueue.class;
+ headOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("head"));
+ tailOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("tail"));
+ sweepVotesOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("sweepVotes"));
+ } catch (Exception e) {
+ throw new Error(e);
}
}
}
--- a/jdk/src/share/classes/java/util/concurrent/Phaser.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/Phaser.java Mon Mar 07 14:48:27 2011 -0800
@@ -1137,18 +1137,16 @@
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long stateOffset =
- objectFieldOffset("state", Phaser.class);
-
- private static long objectFieldOffset(String field, Class<?> klazz) {
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long stateOffset;
+ static {
try {
- return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
- } catch (NoSuchFieldException e) {
- // Convert Exception to corresponding Error
- NoSuchFieldError error = new NoSuchFieldError(field);
- error.initCause(e);
- throw error;
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = Phaser.class;
+ stateOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("state"));
+ } catch (Exception e) {
+ throw new Error(e);
}
}
}
--- a/jdk/src/share/classes/java/util/concurrent/PriorityBlockingQueue.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/PriorityBlockingQueue.java Mon Mar 07 14:48:27 2011 -0800
@@ -963,21 +963,16 @@
}
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long allocationSpinLockOffset =
- objectFieldOffset(UNSAFE, "allocationSpinLock",
- PriorityBlockingQueue.class);
-
- static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
- String field, Class<?> klazz) {
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long allocationSpinLockOffset;
+ static {
try {
- return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
- } catch (NoSuchFieldException e) {
- // Convert Exception to corresponding Error
- NoSuchFieldError error = new NoSuchFieldError(field);
- error.initCause(e);
- throw error;
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = PriorityBlockingQueue.class;
+ allocationSpinLockOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("allocationSpinLock"));
+ } catch (Exception e) {
+ throw new Error(e);
}
}
-
}
--- a/jdk/src/share/classes/java/util/concurrent/SynchronousQueue.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/SynchronousQueue.java Mon Mar 07 14:48:27 2011 -0800
@@ -279,12 +279,22 @@
}
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long nextOffset =
- objectFieldOffset(UNSAFE, "next", SNode.class);
- private static final long matchOffset =
- objectFieldOffset(UNSAFE, "match", SNode.class);
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long matchOffset;
+ private static final long nextOffset;
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = SNode.class;
+ matchOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("match"));
+ nextOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("next"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/** The head (top) of the stack */
@@ -498,10 +508,18 @@
}
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long headOffset =
- objectFieldOffset(UNSAFE, "head", TransferStack.class);
-
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long headOffset;
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = TransferStack.class;
+ headOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("head"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/** Dual Queue */
@@ -558,11 +576,22 @@
}
// Unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long nextOffset =
- objectFieldOffset(UNSAFE, "next", QNode.class);
- private static final long itemOffset =
- objectFieldOffset(UNSAFE, "item", QNode.class);
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long itemOffset;
+ private static final long nextOffset;
+
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = QNode.class;
+ itemOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("item"));
+ nextOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("next"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/** Head of queue */
@@ -791,15 +820,24 @@
}
}
- // unsafe mechanics
- private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
- private static final long headOffset =
- objectFieldOffset(UNSAFE, "head", TransferQueue.class);
- private static final long tailOffset =
- objectFieldOffset(UNSAFE, "tail", TransferQueue.class);
- private static final long cleanMeOffset =
- objectFieldOffset(UNSAFE, "cleanMe", TransferQueue.class);
-
+ private static final sun.misc.Unsafe UNSAFE;
+ private static final long headOffset;
+ private static final long tailOffset;
+ private static final long cleanMeOffset;
+ static {
+ try {
+ UNSAFE = sun.misc.Unsafe.getUnsafe();
+ Class k = TransferQueue.class;
+ headOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("head"));
+ tailOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("tail"));
+ cleanMeOffset = UNSAFE.objectFieldOffset
+ (k.getDeclaredField("cleanMe"));
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
}
/**
--- a/jdk/src/share/classes/java/util/jar/JarFile.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/jar/JarFile.java Mon Mar 07 14:48:27 2011 -0800
@@ -376,9 +376,9 @@
*/
private byte[] getBytes(ZipEntry ze) throws IOException {
byte[] b = new byte[(int)ze.getSize()];
- DataInputStream is = new DataInputStream(super.getInputStream(ze));
- is.readFully(b, 0, b.length);
- is.close();
+ try (DataInputStream is = new DataInputStream(super.getInputStream(ze))) {
+ is.readFully(b, 0, b.length);
+ }
return b;
}
@@ -480,10 +480,10 @@
JarEntry manEntry = getManEntry();
if (manEntry != null) {
byte[] b = new byte[(int)manEntry.getSize()];
- DataInputStream dis = new DataInputStream(
- super.getInputStream(manEntry));
- dis.readFully(b, 0, b.length);
- dis.close();
+ try (DataInputStream dis = new DataInputStream(
+ super.getInputStream(manEntry))) {
+ dis.readFully(b, 0, b.length);
+ }
int last = b.length - src.length;
int i = 0;
--- a/jdk/src/share/classes/java/util/zip/ZipEntry.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/java/util/zip/ZipEntry.java Mon Mar 07 14:48:27 2011 -0800
@@ -26,7 +26,6 @@
package java.util.zip;
import java.util.Date;
-import sun.misc.BootClassLoaderHook;
/**
* This class is used to represent a ZIP file entry.
--- a/jdk/src/share/classes/javax/crypto/SecretKeyFactory.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/javax/crypto/SecretKeyFactory.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -61,7 +61,6 @@
* <p> Every implementation of the Java platform is required to support the
* following standard <code>SecretKeyFactory</code> algorithms:
* <ul>
- * <li><tt>AES</tt></li>
* <li><tt>DES</tt></li>
* <li><tt>DESede</tt></li>
* </ul>
--- a/jdk/src/share/classes/sun/misc/BootClassLoaderHook.java Mon Mar 07 14:46:16 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,141 +0,0 @@
-/*
- * Copyright (c) 2009, 2010, 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. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.misc;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URLStreamHandlerFactory;
-import sun.misc.URLClassPath;
-
-/**
- * BootClassLoaderHook defines an interface for a hook to inject
- * into the bootstrap class loader.
- *
- * With jkernel now removed, no hook is set
- */
-public abstract class BootClassLoaderHook {
- private static BootClassLoaderHook bootLoaderHook = null;
- public static synchronized BootClassLoaderHook getHook() {
- return bootLoaderHook;
- }
-
- public static synchronized void setHook(BootClassLoaderHook hook) {
- if (!VM.isBooted()) {
- throw new InternalError("hook can only be set after VM is booted");
- }
- if (bootLoaderHook != null) {
- throw new InternalError("hook should not be reinitialized");
- }
- bootLoaderHook = hook;
- }
-
- protected BootClassLoaderHook() {
- }
-
- /**
- * A method to be invoked before a class loader loads
- * a bootstrap class.
- *
- * @param classname the binary name of the class
- */
- public static void preLoadClass(String classname) {
- BootClassLoaderHook hook = getHook();
- if (hook != null) {
- hook.loadBootstrapClass(classname);
- }
- }
-
- /**
- * A method to be invoked before a class loader loads
- * a resource.
- *
- * @param resourcename the resource name
- */
- public static void preLoadResource(String resourcename) {
- BootClassLoaderHook hook = getHook();
- if (hook != null) {
- hook.getBootstrapResource(resourcename);
- }
- }
-
- /**
- * A method to be invoked before a library is loaded.
- *
- * @param libname the name of the library
- */
- public static void preLoadLibrary(String libname) {
- BootClassLoaderHook hook = getHook();
- if (hook != null) {
- hook.loadLibrary(libname);
- }
- }
-
- /**
- * Returns a pathname of a JAR or class that the hook loads
- * per this loadClass request; or null.
- *
- * @param classname the binary name of the class
- */
- public abstract String loadBootstrapClass(String className);
-
- /**
- * Returns a pathname of a resource file that the hook loads
- * per this getResource request; or null.
- *
- * @param resourceName the resource name
- */
- public abstract String getBootstrapResource(String resourceName);
-
- /**
- * Returns true if the hook successfully performs an operation per
- * this loadLibrary request; or false if it fails.
- *
- * @param libname the name of the library
- */
- public abstract boolean loadLibrary(String libname);
-
- /**
- * Returns a bootstrap class path constructed by the hook.
- *
- * @param bcp VM's bootstrap class path
- * @param factory Launcher's URL stream handler
- */
- public abstract URLClassPath getBootstrapClassPath(URLClassPath bcp,
- URLStreamHandlerFactory factory);
-
- /**
- * Returns true if the current thread is in the process of doing
- * a prefetching operation.
- */
- public abstract boolean isCurrentThreadPrefetching();
-
- /**
- * Returns true if the hook successfully prefetches the specified file.
- *
- * @param name a platform independent pathname
- */
- public abstract boolean prefetchFile(String name);
-}
--- a/jdk/src/share/classes/sun/misc/JavaSecurityCodeSignerAccess.java Mon Mar 07 14:46:16 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2010, 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. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package sun.misc;
-
-import java.security.CodeSigner;
-import java.security.cert.CRL;
-
-public interface JavaSecurityCodeSignerAccess {
- void setCRLs(CodeSigner signer, CRL[] crls);
- CRL[] getCRLs(CodeSigner signer);
-}
--- a/jdk/src/share/classes/sun/misc/Launcher.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/misc/Launcher.java Mon Mar 07 14:48:27 2011 -0800
@@ -38,7 +38,6 @@
import java.util.Set;
import java.util.Vector;
import java.security.AccessController;
-import java.security.AllPermission;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.security.AccessControlContext;
@@ -117,18 +116,6 @@
return loader;
}
- public static void addURLToAppClassLoader(URL u) {
- AccessController.checkPermission(new AllPermission());
- ClassLoader loader = Launcher.getLauncher().getClassLoader();
- ((Launcher.AppClassLoader) loader).addAppURL(u);
- }
-
- public static void addURLToExtClassLoader(URL u) {
- AccessController.checkPermission(new AllPermission());
- ClassLoader loader = Launcher.getLauncher().getClassLoader();
- ((Launcher.ExtClassLoader) loader.getParent()).addExtURL(u);
- }
-
/*
* The class loader used for loading installed extensions.
*/
@@ -247,11 +234,6 @@
return null;
}
- protected Class findClass(String name) throws ClassNotFoundException {
- BootClassLoaderHook.preLoadClass(name);
- return super.findClass(name);
- }
-
private static AccessControlContext getContext(File[] dirs)
throws IOException
{
@@ -316,7 +298,6 @@
public Class loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
- BootClassLoaderHook.preLoadClass(name);
int i = name.lastIndexOf('.');
if (i != -1) {
SecurityManager sm = System.getSecurityManager();
@@ -373,10 +354,6 @@
return acc;
}
-
- void addAppURL(URL url) {
- super.addURL(url);
- }
}
private static class BootClassPathHolder {
@@ -413,11 +390,7 @@
}
public static URLClassPath getBootstrapClassPath() {
- URLClassPath bcp = BootClassPathHolder.bcp;
- // if DownloadManager is installed, return the bootstrap class path
- // maintained by the Java kernel
- BootClassLoaderHook hook = BootClassLoaderHook.getHook();
- return hook == null ? bcp : hook.getBootstrapClassPath(bcp, factory);
+ return BootClassPathHolder.bcp;
}
private static URL[] pathToURLs(File[] path) {
--- a/jdk/src/share/classes/sun/misc/SharedSecrets.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/misc/SharedSecrets.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -28,7 +28,6 @@
import java.util.jar.JarFile;
import java.io.Console;
import java.io.FileDescriptor;
-import java.security.CodeSigner;
import java.security.ProtectionDomain;
/** A repository of "shared secrets", which are a mechanism for
@@ -49,7 +48,6 @@
private static JavaNioAccess javaNioAccess;
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
- private static JavaSecurityCodeSignerAccess javaSecurityCodeSignerAccess;
public static JavaUtilJarAccess javaUtilJarAccess() {
if (javaUtilJarAccess == null) {
@@ -127,16 +125,4 @@
unsafe.ensureClassInitialized(ProtectionDomain.class);
return javaSecurityProtectionDomainAccess;
}
-
- public static void setJavaSecurityCodeSignerAccess
- (JavaSecurityCodeSignerAccess jscsa) {
- javaSecurityCodeSignerAccess = jscsa;
- }
-
- public static JavaSecurityCodeSignerAccess
- getJavaSecurityCodeSignerAccess() {
- if (javaSecurityCodeSignerAccess == null)
- unsafe.ensureClassInitialized(CodeSigner.class);
- return javaSecurityCodeSignerAccess;
- }
}
--- a/jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java Mon Mar 07 14:48:27 2011 -0800
@@ -69,32 +69,33 @@
*/
private int readChunkHeader () throws IOException {
boolean gotCR = false;
- char c;
+ int c;
char[] len_arr = new char [16];
int len_size = 0;
boolean end_of_len = false;
- while ((c=(char)in.read())!= -1) {
+ while ((c=in.read())!= -1) {
+ char ch = (char) c;
if (len_size == len_arr.length -1) {
throw new IOException ("invalid chunk header");
}
if (gotCR) {
- if (c == LF) {
+ if (ch == LF) {
int l = numeric (len_arr, len_size);
return l;
} else {
gotCR = false;
}
if (!end_of_len) {
- len_arr[len_size++] = c;
+ len_arr[len_size++] = ch;
}
} else {
- if (c == CR) {
+ if (ch == CR) {
gotCR = true;
- } else if (c == ';') {
+ } else if (ch == ';') {
end_of_len = true;
} else if (!end_of_len) {
- len_arr[len_size++] = c;
+ len_arr[len_size++] = ch;
}
}
}
--- a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java Mon Mar 07 14:48:27 2011 -0800
@@ -475,8 +475,8 @@
assert !target.isOpen();
try {
close();
- } catch (IOException ignore) {
- // nothing we can do
+ } catch (Throwable suppressed) {
+ e.addSuppressed(suppressed);
}
throw e;
} catch (IOException ioe) {
--- a/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -42,14 +42,12 @@
* Cipher implementation class. This class currently supports
* DES, DESede, AES, ARCFOUR, and Blowfish.
*
- * This class is designed to support ECB and CBC with NoPadding and
- * PKCS5Padding for both. It will use its own padding impl if the
- * native mechanism does not support padding.
+ * This class is designed to support ECB, CBC, CTR with NoPadding
+ * and ECB, CBC with PKCS5Padding. It will use its own padding impl
+ * if the native mechanism does not support padding.
*
- * Note that PKCS#11 current only supports ECB and CBC. There are no
- * provisions for other modes such as CFB, OFB, PCBC, or CTR mode.
- * However, CTR could be implemented relatively easily (and efficiently)
- * on top of ECB mode in this class, if need be.
+ * Note that PKCS#11 currently only supports ECB, CBC, and CTR.
+ * There are no provisions for other modes such as CFB, OFB, and PCBC.
*
* @author Andreas Sterbenz
* @since 1.5
@@ -60,6 +58,8 @@
private final static int MODE_ECB = 3;
// mode constant for CBC mode
private final static int MODE_CBC = 4;
+ // mode constant for CTR mode
+ private final static int MODE_CTR = 5;
// padding constant for NoPadding
private final static int PAD_NONE = 5;
@@ -157,7 +157,7 @@
private byte[] padBuffer;
private int padBufferLen;
- // original IV, if in MODE_CBC
+ // original IV, if in MODE_CBC or MODE_CTR
private byte[] iv;
// number of bytes buffered internally by the native mechanism and padBuffer
@@ -213,6 +213,8 @@
("CBC mode not supported with stream ciphers");
}
result = MODE_CBC;
+ } else if (mode.equals("CTR")) {
+ result = MODE_CTR;
} else {
throw new NoSuchAlgorithmException("Unsupported mode " + mode);
}
@@ -228,6 +230,10 @@
if (padding.equals("NOPADDING")) {
paddingType = PAD_NONE;
} else if (padding.equals("PKCS5PADDING")) {
+ if (this.blockMode == MODE_CTR) {
+ throw new NoSuchPaddingException
+ ("PKCS#5 padding not supported with CTR mode");
+ }
paddingType = PAD_PKCS5;
if (mechanism != CKM_DES_CBC_PAD && mechanism != CKM_DES3_CBC_PAD &&
mechanism != CKM_AES_CBC_PAD) {
@@ -348,11 +354,14 @@
("IV not used in ECB mode");
}
}
- } else { // MODE_CBC
+ } else { // MODE_CBC or MODE_CTR
if (iv == null) {
if (encrypt == false) {
- throw new InvalidAlgorithmParameterException
- ("IV must be specified for decryption in CBC mode");
+ String exMsg =
+ (blockMode == MODE_CBC ?
+ "IV must be specified for decryption in CBC mode" :
+ "IV must be specified for decryption in CTR mode");
+ throw new InvalidAlgorithmParameterException(exMsg);
}
// generate random IV
if (random == null) {
@@ -410,13 +419,15 @@
if (session == null) {
session = token.getOpSession();
}
+ CK_MECHANISM mechParams = (blockMode == MODE_CTR?
+ new CK_MECHANISM(mechanism, new CK_AES_CTR_PARAMS(iv)) :
+ new CK_MECHANISM(mechanism, iv));
+
try {
if (encrypt) {
- token.p11.C_EncryptInit(session.id(),
- new CK_MECHANISM(mechanism, iv), p11Key.keyID);
+ token.p11.C_EncryptInit(session.id(), mechParams, p11Key.keyID);
} else {
- token.p11.C_DecryptInit(session.id(),
- new CK_MECHANISM(mechanism, iv), p11Key.keyID);
+ token.p11.C_DecryptInit(session.id(), mechParams, p11Key.keyID);
}
} catch (PKCS11Exception ex) {
// release session when initialization failed
--- a/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -62,6 +62,11 @@
// mode constant for public key decryption (verifying)
private final static int MODE_VERIFY = 4;
+ // padding type constant for NoPadding
+ private final static int PAD_NONE = 1;
+ // padding type constant for PKCS1Padding
+ private final static int PAD_PKCS1 = 2;
+
// token instance
private final Token token;
@@ -77,6 +82,9 @@
// mode, one of MODE_* above
private int mode;
+ // padding, one of PAD_* above
+ private int padType;
+
private byte[] buffer;
private int bufOfs;
@@ -113,8 +121,10 @@
protected void engineSetPadding(String padding)
throws NoSuchPaddingException {
String lowerPadding = padding.toLowerCase(Locale.ENGLISH);
- if (lowerPadding.equals("pkcs1Padding")) {
- // empty
+ if (lowerPadding.equals("pkcs1padding")) {
+ padType = PAD_PKCS1;
+ } else if (lowerPadding.equals("nopadding")) {
+ padType = PAD_NONE;
} else {
throw new NoSuchPaddingException("Unsupported padding " + padding);
}
@@ -209,7 +219,8 @@
int n = (p11Key.keyLength() + 7) >> 3;
outputSize = n;
buffer = new byte[n];
- maxInputSize = encrypt ? (n - PKCS1_MIN_PADDING_LENGTH) : n;
+ maxInputSize = ((padType == PAD_PKCS1 && encrypt) ?
+ (n - PKCS1_MIN_PADDING_LENGTH) : n);
try {
initialize();
} catch (PKCS11Exception e) {
--- a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -621,12 +621,16 @@
m(CKM_AES_CBC_PAD, CKM_AES_CBC));
d(CIP, "AES/ECB", P11Cipher, s("AES"),
m(CKM_AES_ECB));
+ d(CIP, "AES/CTR/NoPadding", P11Cipher,
+ m(CKM_AES_CTR));
d(CIP, "Blowfish/CBC", P11Cipher,
m(CKM_BLOWFISH_CBC));
// XXX RSA_X_509, RSA_OAEP not yet supported
- d(CIP, "RSA/ECB/PKCS1Padding", P11RSACipher,
+ d(CIP, "RSA/ECB/PKCS1Padding", P11RSACipher, s("RSA"),
m(CKM_RSA_PKCS));
+ d(CIP, "RSA/ECB/NoPadding", P11RSACipher,
+ m(CKM_RSA_X_509));
d(SIG, "RawDSA", P11Signature, s("NONEwithDSA"),
m(CKM_DSA));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS.java Mon Mar 07 14:48:27 2011 -0800
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sun.security.pkcs11.wrapper;
+
+/**
+ * This class represents the necessary parameters required by
+ * the CKM_AES_CTR mechanism as defined in CK_AES_CTR_PARAMS structure.<p>
+ * <B>PKCS#11 structure:</B>
+ * <PRE>
+ * typedef struct CK_AES_CTR_PARAMS {
+ * CK_ULONG ulCounterBits;
+ * CK_BYTE cb[16];
+ * } CK_AES_CTR_PARAMS;
+ * </PRE>
+ *
+ * @author Yu-Ching Valerie Peng
+ * @since 1.7
+ */
+public class CK_AES_CTR_PARAMS {
+
+ private final long ulCounterBits;
+ private final byte cb[];
+
+ public CK_AES_CTR_PARAMS(byte[] cb) {
+ ulCounterBits = 128;
+ this.cb = cb.clone();
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append(Constants.INDENT);
+ buffer.append("ulCounterBits: ");
+ buffer.append(ulCounterBits);
+ buffer.append(Constants.NEWLINE);
+
+ buffer.append(Constants.INDENT);
+ buffer.append("cb: ");
+ buffer.append(Functions.toHexString(cb));
+
+ return buffer.toString();
+ }
+}
--- a/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@@ -48,6 +48,7 @@
package sun.security.pkcs11.wrapper;
import java.math.BigInteger;
+import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
/**
* class CK_MECHANISM specifies a particular mechanism and any parameters it
@@ -127,6 +128,10 @@
init(mechanism, params);
}
+ public CK_MECHANISM(long mechanism, CK_AES_CTR_PARAMS params) {
+ init(mechanism, params);
+ }
+
private void init(long mechanism, Object pParameter) {
this.mechanism = mechanism;
this.pParameter = pParameter;
--- a/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@@ -47,8 +47,6 @@
package sun.security.pkcs11.wrapper;
-
-
/**
* This interface holds constants of the PKCS#11 v2.11 standard.
* This is mainly the content of the 'pkcs11t.h' header file.
@@ -306,6 +304,10 @@
public static final long CKK_VENDOR_DEFINED = 0x80000000L;
+ // new for v2.20 amendment 3
+ //public static final long CKK_CAMELLIA = 0x00000025L;
+ //public static final long CKK_ARIA = 0x00000026L;
+
// pseudo key type ANY (for template manager)
public static final long PCKK_ANY = 0x7FFFFF22L;
@@ -690,6 +692,34 @@
public static final long CKM_VENDOR_DEFINED = 0x80000000L;
+ // new for v2.20 amendment 3
+ public static final long CKM_SHA224 = 0x00000255L;
+ public static final long CKM_SHA224_HMAC = 0x00000256L;
+ public static final long CKM_SHA224_HMAC_GENERAL = 0x00000257L;
+ public static final long CKM_SHA224_KEY_DERIVATION = 0x00000396L;
+ public static final long CKM_SHA224_RSA_PKCS = 0x00000046L;
+ public static final long CKM_SHA224_RSA_PKCS_PSS = 0x00000047L;
+ public static final long CKM_AES_CTR = 0x00001086L;
+ /*
+ public static final long CKM_CAMELLIA_KEY_GEN = 0x00000550L;
+ public static final long CKM_CAMELLIA_ECB = 0x00000551L;
+ public static final long CKM_CAMELLIA_CBC = 0x00000552L;
+ public static final long CKM_CAMELLIA_MAC = 0x00000553L;
+ public static final long CKM_CAMELLIA_MAC_GENERAL = 0x00000554L;
+ public static final long CKM_CAMELLIA_CBC_PAD = 0x00000555L;
+ public static final long CKM_CAMELLIA_ECB_ENCRYPT_DATA = 0x00000556L;
+ public static final long CKM_CAMELLIA_CBC_ENCRYPT_DATA = 0x00000557L;
+ public static final long CKM_CAMELLIA_CTR = 0x00000558L;
+ public static final long CKM_ARIA_KEY_GEN = 0x00000560L;
+ public static final long CKM_ARIA_ECB = 0x00000561L;
+ public static final long CKM_ARIA_CBC = 0x00000562L;
+ public static final long CKM_ARIA_MAC = 0x00000563L;
+ public static final long CKM_ARIA_MAC_GENERAL = 0x00000564L;
+ public static final long CKM_ARIA_CBC_PAD = 0x00000565L;
+ public static final long CKM_ARIA_ECB_ENCRYPT_DATA = 0x00000566L;
+ public static final long CKM_ARIA_CBC_ENCRYPT_DATA = 0x00000567L;
+ */
+
// NSS private
public static final long CKM_NSS_TLS_PRF_GENERAL = 0x80000373L;
@@ -881,7 +911,8 @@
/* The following MGFs are defined */
public static final long CKG_MGF1_SHA1 = 0x00000001L;
-
+ // new for v2.20 amendment 3
+ public static final long CKG_MGF1_SHA224 = 0x00000005L;
/* The following encoding parameter sources are defined */
public static final long CKZ_DATA_SPECIFIED = 0x00000001L;
--- a/jdk/src/share/classes/sun/security/tools/JarSigner.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/tools/JarSigner.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -26,7 +26,6 @@
package sun.security.tools;
import java.io.*;
-import java.security.cert.X509CRL;
import java.util.*;
import java.util.zip.*;
import java.util.jar.*;
@@ -36,7 +35,6 @@
import java.text.Collator;
import java.text.MessageFormat;
import java.security.cert.Certificate;
-import java.security.cert.CRL;
import java.security.cert.X509Certificate;
import java.security.cert.CertificateException;
import java.security.*;
@@ -58,7 +56,6 @@
import sun.security.x509.*;
import sun.security.util.*;
import sun.misc.BASE64Encoder;
-import sun.misc.SharedSecrets;
/**
@@ -117,13 +114,11 @@
static final int SIGNED_BY_ALIAS = 0x08; // signer is in alias list
X509Certificate[] certChain; // signer's cert chain (when composing)
- Set<X509CRL> crls; // signer provided CRLs
PrivateKey privateKey; // private key
KeyStore store; // the keystore specified by -keystore
// or the default keystore, never null
String keystore; // key store file
- List<String> crlfiles = new ArrayList<>(); // CRL files to add
boolean nullStream = false; // null keystore input stream (NONE)
boolean token = false; // token-based keystore
String jarfile; // jar files to sign or verify
@@ -151,7 +146,6 @@
boolean signManifest = true; // "sign" the whole manifest
boolean externalSF = true; // leave the .SF out of the PKCS7 block
boolean strict = false; // treat warnings as error
- boolean autoCRL = false; // Automatcially add CRL defined in cert
// read zip entry raw bytes
private ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
@@ -232,29 +226,6 @@
} else {
loadKeyStore(keystore, true);
getAliasInfo(alias);
- crls = new HashSet<X509CRL>();
- if (crlfiles.size() > 0 || autoCRL) {
- CertificateFactory fac =
- CertificateFactory.getInstance("X509");
- List<CRL> list = new ArrayList<>();
- for (String file: crlfiles) {
- Collection<? extends CRL> tmp = KeyTool.loadCRLs(file);
- for (CRL crl: tmp) {
- if (crl instanceof X509CRL) {
- crls.add((X509CRL)crl);
- }
- }
- }
- if (autoCRL) {
- List<CRL> crlsFromCert =
- KeyTool.readCRLsFromCert(certChain[0]);
- for (CRL crl: crlsFromCert) {
- if (crl instanceof X509CRL) {
- crls.add((X509CRL)crl);
- }
- }
- }
- }
// load the alternative signing mechanism
if (altSignerClass != null) {
@@ -396,13 +367,6 @@
} else if (collator.compare(flags, "-digestalg") ==0) {
if (++n == args.length) usageNoArg();
digestalg = args[n];
- } else if (collator.compare(flags, "-crl") ==0) {
- if ("auto".equals(modifier)) {
- autoCRL = true;
- } else {
- if (++n == args.length) usageNoArg();
- crlfiles.add(args[n]);
- }
} else if (collator.compare(flags, "-certs") ==0) {
showcerts = true;
} else if (collator.compare(flags, "-strict") ==0) {
@@ -549,9 +513,6 @@
(".sigalg.algorithm.name.of.signature.algorithm"));
System.out.println();
System.out.println(rb.getString
- (".crl.auto.file.include.CRL.in.signed.jar"));
- System.out.println();
- System.out.println(rb.getString
(".verify.verify.a.signed.JAR.file"));
System.out.println();
System.out.println(rb.getString
@@ -691,20 +652,6 @@
if (showcerts) {
sb.append(si);
sb.append('\n');
- CRL[] crls = SharedSecrets
- .getJavaSecurityCodeSignerAccess()
- .getCRLs(signer);
- if (crls != null) {
- for (CRL crl: crls) {
- if (crl instanceof X509CRLImpl) {
- sb.append(tab).append("[");
- sb.append(String.format(
- rb.getString("with.a.CRL.including.d.entries"),
- ((X509CRLImpl)crl).getRevokedCertificates().size()))
- .append("]\n");
- }
- }
- }
}
}
} else if (showcerts && !verbose.equals("all")) {
@@ -1284,7 +1231,7 @@
try {
block =
- sf.generateBlock(privateKey, sigalg, certChain, crls,
+ sf.generateBlock(privateKey, sigalg, certChain,
externalSF, tsaUrl, tsaCert, signingMechanism, args,
zipFile);
} catch (SocketTimeoutException e) {
@@ -2249,7 +2196,6 @@
public Block generateBlock(PrivateKey privateKey,
String sigalg,
X509Certificate[] certChain,
- Set<X509CRL> crls,
boolean externalSF, String tsaUrl,
X509Certificate tsaCert,
ContentSigner signingMechanism,
@@ -2257,7 +2203,7 @@
throws NoSuchAlgorithmException, InvalidKeyException, IOException,
SignatureException, CertificateException
{
- return new Block(this, privateKey, sigalg, certChain, crls, externalSF,
+ return new Block(this, privateKey, sigalg, certChain, externalSF,
tsaUrl, tsaCert, signingMechanism, args, zipFile);
}
@@ -2271,8 +2217,7 @@
* Construct a new signature block.
*/
Block(SignatureFile sfg, PrivateKey privateKey, String sigalg,
- X509Certificate[] certChain, Set<X509CRL> crls,
- boolean externalSF, String tsaUrl,
+ X509Certificate[] certChain, boolean externalSF, String tsaUrl,
X509Certificate tsaCert, ContentSigner signingMechanism,
String[] args, ZipFile zipFile)
throws NoSuchAlgorithmException, InvalidKeyException, IOException,
@@ -2359,7 +2304,7 @@
// Assemble parameters for the signing mechanism
ContentSignerParameters params =
new JarSignerParameters(args, tsaUri, tsaCert, signature,
- signatureAlgorithm, certChain, crls, content, zipFile);
+ signatureAlgorithm, certChain, content, zipFile);
// Generate the signature block
block = signingMechanism.generateSignedData(
@@ -2400,7 +2345,6 @@
private byte[] signature;
private String signatureAlgorithm;
private X509Certificate[] signerCertificateChain;
- private Set<X509CRL> crls;
private byte[] content;
private ZipFile source;
@@ -2409,8 +2353,7 @@
*/
JarSignerParameters(String[] args, URI tsa, X509Certificate tsaCertificate,
byte[] signature, String signatureAlgorithm,
- X509Certificate[] signerCertificateChain, Set<X509CRL> crls,
- byte[] content,
+ X509Certificate[] signerCertificateChain, byte[] content,
ZipFile source) {
if (signature == null || signatureAlgorithm == null ||
@@ -2423,7 +2366,6 @@
this.signature = signature;
this.signatureAlgorithm = signatureAlgorithm;
this.signerCertificateChain = signerCertificateChain;
- this.crls = crls;
this.content = content;
this.source = source;
}
@@ -2499,13 +2441,4 @@
public ZipFile getSource() {
return source;
}
-
- @Override
- public Set<X509CRL> getCRLs() {
- if (crls == null) {
- return Collections.emptySet();
- } else {
- return Collections.unmodifiableSet(crls);
- }
- }
}
--- a/jdk/src/share/classes/sun/security/tools/JarSignerResources.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/tools/JarSignerResources.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -74,8 +74,6 @@
"[-digestalg <algorithm>] name of digest algorithm"},
{".sigalg.algorithm.name.of.signature.algorithm",
"[-sigalg <algorithm>] name of signature algorithm"},
- {".crl.auto.file.include.CRL.in.signed.jar",
- "[-crl[:auto| <file>] include CRL in signed jar"},
{".verify.verify.a.signed.JAR.file",
"[-verify] verify a signed JAR file"},
{".verbose.suboptions.verbose.output.when.signing.verifying.",
@@ -193,7 +191,6 @@
{"using.an.alternative.signing.mechanism",
"using an alternative signing mechanism"},
{"entry.was.signed.on", "entry was signed on {0}"},
- {"with.a.CRL.including.d.entries", "with a CRL including %d entries"},
{"Warning.", "Warning: "},
{"This.jar.contains.unsigned.entries.which.have.not.been.integrity.checked.",
"This jar contains unsigned entries which have not been integrity-checked. "},
--- a/jdk/src/share/classes/sun/security/tools/KeyTool.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/tools/KeyTool.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -25,7 +25,6 @@
package sun.security.tools;
-import sun.misc.SharedSecrets;
import java.io.*;
import java.security.CodeSigner;
import java.security.KeyStore;
@@ -2311,16 +2310,6 @@
out.println();
}
}
- CRL[] crls = SharedSecrets
- .getJavaSecurityCodeSignerAccess()
- .getCRLs(signer);
- if (crls != null) {
- out.println(rb.getString("CRLs."));
- out.println();
- for (CRL crl: crls) {
- printCRL(crl, out);
- }
- }
}
}
}
--- a/jdk/src/share/classes/sun/security/tools/TimestampedSigner.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/tools/TimestampedSigner.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -38,7 +38,6 @@
import java.util.List;
import com.sun.jarsigner.*;
-import java.security.cert.X509CRL;
import java.util.Arrays;
import sun.security.pkcs.*;
import sun.security.timestamp.*;
@@ -238,9 +237,8 @@
AlgorithmId[] algorithms = {digestAlgorithmId};
// Create the PKCS #7 signed data message
- PKCS7 p7 =
- new PKCS7(algorithms, contentInfo, signerCertificateChain,
- parameters.getCRLs().toArray(new X509CRL[parameters.getCRLs().size()]), signerInfos);
+ PKCS7 p7 = new PKCS7(algorithms, contentInfo, signerCertificateChain,
+ null, signerInfos);
ByteArrayOutputStream p7out = new ByteArrayOutputStream();
p7.encodeSignedData(p7out);
--- a/jdk/src/share/classes/sun/security/util/SignatureFileVerifier.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/security/util/SignatureFileVerifier.java Mon Mar 07 14:48:27 2011 -0800
@@ -37,7 +37,6 @@
import sun.security.pkcs.*;
import sun.security.timestamp.TimestampToken;
import sun.misc.BASE64Decoder;
-import sun.misc.SharedSecrets;
import sun.security.jca.Providers;
@@ -486,12 +485,7 @@
signers = new ArrayList<CodeSigner>();
}
// Append the new code signer
- CodeSigner signer = new CodeSigner(certChain, getTimestamp(info));
- if (block.getCRLs() != null) {
- SharedSecrets.getJavaSecurityCodeSignerAccess().setCRLs(
- signer, block.getCRLs());
- }
- signers.add(signer);
+ signers.add(new CodeSigner(certChain, getTimestamp(info)));
if (debug != null) {
debug.println("Signature Block Certificate: " +
--- a/jdk/src/share/classes/sun/tools/native2ascii/Main.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/tools/native2ascii/Main.java Mon Mar 07 14:48:27 2011 -0800
@@ -94,7 +94,7 @@
* Run the converter
*/
public synchronized boolean convert(String argv[]){
- Vector v = new Vector(2);
+ List<String> v = new ArrayList<>(2);
File outputFile = null;
boolean createOutputFile = false;
@@ -115,7 +115,7 @@
usage();
return false;
}
- v.addElement(argv[i]);
+ v.add(argv[i]);
}
}
if (encodingString == null)
@@ -126,11 +126,11 @@
initializeConverter();
if (v.size() == 1)
- inputFileName = (String)v.elementAt(0);
+ inputFileName = v.get(0);
if (v.size() == 2) {
- inputFileName = (String)v.elementAt(0);
- outputFileName = (String)v.elementAt(1);
+ inputFileName = v.get(0);
+ outputFileName = v.get(1);
createOutputFile = true;
}
@@ -363,9 +363,7 @@
private String formatMsg(String key, String arg) {
String msg = getMsg(key);
- String[] args = new String[1];
- args[0] = arg;
- return MessageFormat.format(msg, (Object)args);
+ return MessageFormat.format(msg, arg);
}
--- a/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java Mon Mar 07 14:48:27 2011 -0800
@@ -127,7 +127,9 @@
calendarProps = (Properties) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
Properties props = new Properties();
- props.load(new FileInputStream(fname));
+ try (FileInputStream fis = new FileInputStream(fname)) {
+ props.load(fis);
+ }
return props;
}
});
--- a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipDirectoryStream.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipDirectoryStream.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -76,7 +76,7 @@
} catch (IOException e) {
throw new IllegalStateException(e);
}
- return new Iterator<>() {
+ return new Iterator<Path>() {
private Path next;
@Override
public boolean hasNext() {
--- a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java Mon Mar 07 14:48:27 2011 -0800
@@ -112,11 +112,8 @@
}
// sm and existence check
zfpath.getFileSystem().provider().checkAccess(zfpath, AccessMode.READ);
- try {
- zfpath.getFileSystem().provider().checkAccess(zfpath, AccessMode.WRITE);
- } catch (AccessDeniedException x) {
+ if (!Files.isWritable(zfpath))
this.readOnly = true;
- }
this.zc = ZipCoder.get(nameEncoding);
this.defaultdir = new ZipPath(this, getBytes(defaultDir));
this.ch = Files.newByteChannel(zfpath, READ);
--- a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -590,7 +590,7 @@
@Override
public Iterator<Path> iterator() {
- return new Iterator<>() {
+ return new Iterator<Path>() {
private int i = 0;
@Override
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@@ -695,6 +695,46 @@
}
/*
+ * converts the Java CK_AES_CTR_PARAMS object to a CK_AES_CTR_PARAMS structure
+ *
+ * @param env - used to call JNI funktions to get the Java classes and objects
+ * @param jParam - the Java CK_AES_CTR_PARAMS object to convert
+ * @param ckpParam - pointer to the new CK_AES_CTR_PARAMS structure
+ */
+void jAesCtrParamsToCKAesCtrParam(JNIEnv *env, jobject jParam,
+ CK_AES_CTR_PARAMS_PTR ckpParam) {
+ jclass jAesCtrParamsClass;
+ jfieldID fieldID;
+ jlong jCounterBits;
+ jobject jCb;
+ CK_BYTE_PTR ckBytes;
+ CK_ULONG ckTemp;
+
+ /* get ulCounterBits */
+ jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS);
+ if (jAesCtrParamsClass == NULL) { return; }
+ fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "ulCounterBits", "J");
+ if (fieldID == NULL) { return; }
+ jCounterBits = (*env)->GetLongField(env, jParam, fieldID);
+
+ /* get cb */
+ fieldID = (*env)->GetFieldID(env, jAesCtrParamsClass, "cb", "[B");
+ if (fieldID == NULL) { return; }
+ jCb = (*env)->GetObjectField(env, jParam, fieldID);
+
+ /* populate java values */
+ ckpParam->ulCounterBits = jLongToCKULong(jCounterBits);
+ jByteArrayToCKByteArray(env, jCb, &ckBytes, &ckTemp);
+ if ((*env)->ExceptionCheck(env)) { return; }
+ if (ckTemp != 16) {
+ TRACE1("ERROR: WRONG CTR IV LENGTH %d", ckTemp);
+ } else {
+ memcpy(ckpParam->cb, ckBytes, ckTemp);
+ free(ckBytes);
+ }
+}
+
+/*
* converts a Java CK_MECHANISM object into a CK_MECHANISM structure
*
* @param env - used to call JNI funktions to get the values out of the Java object
@@ -937,12 +977,10 @@
{
/* get all Java mechanism parameter classes */
jclass jVersionClass, jSsl3MasterKeyDeriveParamsClass, jSsl3KeyMatParamsClass;
- jclass jTlsPrfParamsClass, jRsaPkcsOaepParamsClass, jPbeParamsClass;
- jclass jPkcs5Pbkd2ParamsClass, jRsaPkcsPssParamsClass;
+ jclass jTlsPrfParamsClass, jAesCtrParamsClass, jRsaPkcsOaepParamsClass;
+ jclass jPbeParamsClass, jPkcs5Pbkd2ParamsClass, jRsaPkcsPssParamsClass;
jclass jEcdh1DeriveParamsClass, jEcdh2DeriveParamsClass;
jclass jX942Dh1DeriveParamsClass, jX942Dh2DeriveParamsClass;
-
- /* get all Java mechanism parameter classes */
TRACE0("\nDEBUG: jMechanismParameterToCKMechanismParameter");
/* most common cases, i.e. NULL/byte[]/long, are already handled by
@@ -1046,6 +1084,33 @@
return;
}
+ jAesCtrParamsClass = (*env)->FindClass(env, CLASS_AES_CTR_PARAMS);
+ if (jAesCtrParamsClass == NULL) { return; }
+ if ((*env)->IsInstanceOf(env, jParam, jAesCtrParamsClass)) {
+ /*
+ * CK_AES_CTR_PARAMS
+ */
+ CK_AES_CTR_PARAMS_PTR ckpParam;
+
+ ckpParam = (CK_AES_CTR_PARAMS_PTR) malloc(sizeof(CK_AES_CTR_PARAMS));
+ if (ckpParam == NULL) {
+ JNU_ThrowOutOfMemoryError(env, 0);
+ return;
+ }
+
+ /* convert jParameter to CKParameter */
+ jAesCtrParamsToCKAesCtrParam(env, jParam, ckpParam);
+ if ((*env)->ExceptionCheck(env)) {
+ free(ckpParam);
+ return;
+ }
+
+ /* get length and pointer of parameter */
+ *ckpLength = sizeof(CK_AES_CTR_PARAMS);
+ *ckpParamPtr = ckpParam;
+ return;
+ }
+
jRsaPkcsOaepParamsClass = (*env)->FindClass(env, CLASS_RSA_PKCS_OAEP_PARAMS);
if (jRsaPkcsOaepParamsClass == NULL) { return; }
if ((*env)->IsInstanceOf(env, jParam, jRsaPkcsOaepParamsClass)) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs-11v2-20a3.h Mon Mar 07 14:48:27 2011 -0800
@@ -0,0 +1,124 @@
+/* pkcs-11v2-20a3.h include file for the PKCS #11 Version 2.20 Amendment 3
+ document. */
+
+/* $Revision: 1.4 $ */
+
+/* License to copy and use this software is granted provided that it is
+ * identified as "RSA Security Inc. PKCS #11 Cryptographic Token Interface
+ * (Cryptoki) Version 2.20 Amendment 3" in all material mentioning or
+ * referencing this software.
+
+ * RSA Security Inc. makes no representations concerning either the
+ * merchantability of this software or the suitability of this software for
+ * any particular purpose. It is provided "as is" without express or implied
+ * warranty of any kind.
+ */
+
+/* This file is preferably included after inclusion of pkcs11.h */
+
+#ifndef _PKCS_11V2_20A3_H_
+#define _PKCS_11V2_20A3_H_ 1
+
+/* Are the definitions of this file already included in pkcs11t.h ? */
+#ifndef CKK_CAMELLIA
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Key types */
+
+/* Camellia is new for PKCS #11 v2.20 amendment 3 */
+#define CKK_CAMELLIA 0x00000025
+/* ARIA is new for PKCS #11 v2.20 amendment 3 */
+#define CKK_ARIA 0x00000026
+
+
+/* Mask-generating functions */
+
+/* SHA-224 is new for PKCS #11 v2.20 amendment 3 */
+#define CKG_MGF1_SHA224 0x00000005
+
+
+/* Mechanism Identifiers */
+
+/* SHA-224 is new for PKCS #11 v2.20 amendment 3 */
+#define CKM_SHA224 0x00000255
+#define CKM_SHA224_HMAC 0x00000256
+#define CKM_SHA224_HMAC_GENERAL 0x00000257
+
+/* SHA-224 key derivation is new for PKCS #11 v2.20 amendment 3 */
+#define CKM_SHA224_KEY_DERIVATION 0x00000396
+
+/* SHA-224 RSA mechanisms are new for PKCS #11 v2.20 amendment 3 */
+#define CKM_SHA224_RSA_PKCS 0x00000046
+#define CKM_SHA224_RSA_PKCS_PSS 0x00000047
+
+/* AES counter mode is new for PKCS #11 v2.20 amendment 3 */
+#define CKM_AES_CTR 0x00001086
+
+/* Camellia is new for PKCS #11 v2.20 amendment 3 */
+#define CKM_CAMELLIA_KEY_GEN 0x00000550
+#define CKM_CAMELLIA_ECB 0x00000551
+#define CKM_CAMELLIA_CBC 0x00000552
+#define CKM_CAMELLIA_MAC 0x00000553
+#define CKM_CAMELLIA_MAC_GENERAL 0x00000554
+#define CKM_CAMELLIA_CBC_PAD 0x00000555
+#define CKM_CAMELLIA_ECB_ENCRYPT_DATA 0x00000556
+#define CKM_CAMELLIA_CBC_ENCRYPT_DATA 0x00000557
+#define CKM_CAMELLIA_CTR 0x00000558
+
+/* ARIA is new for PKCS #11 v2.20 amendment 3 */
+#define CKM_ARIA_KEY_GEN 0x00000560
+#define CKM_ARIA_ECB 0x00000561
+#define CKM_ARIA_CBC 0x00000562
+#define CKM_ARIA_MAC 0x00000563
+#define CKM_ARIA_MAC_GENERAL 0x00000564
+#define CKM_ARIA_CBC_PAD 0x00000565
+#define CKM_ARIA_ECB_ENCRYPT_DATA 0x00000566
+#define CKM_ARIA_CBC_ENCRYPT_DATA 0x00000567
+
+
+/* Mechanism parameters */
+
+/* CK_AES_CTR_PARAMS is new for PKCS #11 v2.20 amendment 3 */
+typedef struct CK_AES_CTR_PARAMS {
+ CK_ULONG ulCounterBits;
+ CK_BYTE cb[16];
+} CK_AES_CTR_PARAMS;
+
+typedef CK_AES_CTR_PARAMS CK_PTR CK_AES_CTR_PARAMS_PTR;
+
+/* CK_CAMELLIA_CTR_PARAMS is new for PKCS #11 v2.20 amendment 3 */
+typedef struct CK_CAMELLIA_CTR_PARAMS {
+ CK_ULONG ulCounterBits;
+ CK_BYTE cb[16];
+} CK_CAMELLIA_CTR_PARAMS;
+
+typedef CK_CAMELLIA_CTR_PARAMS CK_PTR CK_CAMELLIA_CTR_PARAMS_PTR;
+
+/* CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS is new for PKCS #11 v2.20 amendment 3 */
+typedef struct CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS {
+ CK_BYTE iv[16];
+ CK_BYTE_PTR pData;
+ CK_ULONG length;
+} CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS;
+
+typedef CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_CAMELLIA_CBC_ENCRYPT_DATA_PARAMS_PTR;
+
+/* CK_ARIA_CBC_ENCRYPT_DATA_PARAMS is new for PKCS #11 v2.20 amendment 3 */
+typedef struct CK_ARIA_CBC_ENCRYPT_DATA_PARAMS {
+ CK_BYTE iv[16];
+ CK_BYTE_PTR pData;
+ CK_ULONG length;
+} CK_ARIA_CBC_ENCRYPT_DATA_PARAMS;
+
+typedef CK_ARIA_CBC_ENCRYPT_DATA_PARAMS CK_PTR CK_ARIA_CBC_ENCRYPT_DATA_PARAMS_PTR;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
*/
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
@@ -153,6 +153,7 @@
#include "p11_md.h"
#include "pkcs11.h"
+#include "pkcs-11v2-20a3.h"
#include <jni.h>
#include <jni_util.h>
@@ -272,6 +273,7 @@
#define CLASS_SSL3_MASTER_KEY_DERIVE_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_MASTER_KEY_DERIVE_PARAMS"
#define CLASS_SSL3_KEY_MAT_PARAMS "sun/security/pkcs11/wrapper/CK_SSL3_KEY_MAT_PARAMS"
#define CLASS_TLS_PRF_PARAMS "sun/security/pkcs11/wrapper/CK_TLS_PRF_PARAMS"
+#define CLASS_AES_CTR_PARAMS "sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS"
/* function to convert a PKCS#11 return value other than CK_OK into a Java Exception
* or to throw a PKCS11RuntimeException
--- a/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java Mon Mar 07 14:48:27 2011 -0800
@@ -571,9 +571,9 @@
long newLastSyncTime = 0;
try {
newLastSyncTime = prefsFile.lastModified();
- FileInputStream fis = new FileInputStream(prefsFile);
- XmlSupport.importMap(fis, m);
- fis.close();
+ try (FileInputStream fis = new FileInputStream(prefsFile)) {
+ XmlSupport.importMap(fis, m);
+ }
} catch(Exception e) {
if (e instanceof InvalidPreferencesFormatException) {
getLogger().warning("Invalid preferences format in "
@@ -618,9 +618,9 @@
if (!dir.exists() && !dir.mkdirs())
throw new BackingStoreException(dir +
" create failed.");
- FileOutputStream fos = new FileOutputStream(tmpFile);
- XmlSupport.exportMap(fos, prefsCache);
- fos.close();
+ try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
+ XmlSupport.exportMap(fos, prefsCache);
+ }
if (!tmpFile.renameTo(prefsFile))
throw new BackingStoreException("Can't rename " +
tmpFile + " to " + prefsFile);
--- a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java Mon Mar 07 14:48:27 2011 -0800
@@ -236,7 +236,9 @@
} catch (SecurityException x) {
try {
ch.close();
- } catch (IOException ignore) { }
+ } catch (Throwable suppressed) {
+ x.addSuppressed(suppressed);
+ }
throw x;
}
return ch;
--- a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java Mon Mar 07 14:48:27 2011 -0800
@@ -137,7 +137,7 @@
return port;
}
- // register for events if there are outstanding I/O operations
+ // register events for outstanding I/O operations, caller already owns updateLock
private void updateEvents() {
assert Thread.holdsLock(updateLock);
int events = 0;
@@ -149,6 +149,13 @@
port.startPoll(fdVal, events);
}
+ // register events for outstanding I/O operations
+ private void lockAndUpdateEvents() {
+ synchronized (updateLock) {
+ updateEvents();
+ }
+ }
+
// invoke to finish read and/or write operations
private void finish(boolean mayInvokeDirect,
boolean readable,
@@ -255,10 +262,11 @@
// close channel if connection cannot be established
try {
close();
- } catch (IOException ignore) { }
+ } catch (Throwable suppressed) {
+ e.addSuppressed(suppressed);
+ }
}
-
// invoke handler and set result
CompletionHandler<Void,Object> handler = connectHandler;
Object att = connectAttachment;
@@ -345,7 +353,9 @@
if (e != null) {
try {
close();
- } catch (IOException ignore) { }
+ } catch (Throwable suppressed) {
+ e.addSuppressed(suppressed);
+ }
}
if (handler == null) {
return CompletedFuture.withResult(null, e);
@@ -399,9 +409,8 @@
exc = x;
} finally {
// restart poll in case of concurrent write
- synchronized (updateLock) {
- updateEvents();
- }
+ if (!(exc instanceof AsynchronousCloseException))
+ lockAndUpdateEvents();
end();
}
@@ -595,9 +604,8 @@
exc = x;
} finally {
// restart poll in case of concurrent write
- synchronized (updateLock) {
- updateEvents();
- }
+ if (!(exc instanceof AsynchronousCloseException))
+ lockAndUpdateEvents();
end();
}
--- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -77,22 +77,24 @@
*/
#endif /* __linux__ */
struct hostent res, res2, *hp;
- char buf[HENT_BUF_SIZE];
- char buf2[HENT_BUF_SIZE];
+ // these buffers must be pointer-aligned so they are declared
+ // with pointer type
+ char *buf[HENT_BUF_SIZE/(sizeof (char *))];
+ char *buf2[HENT_BUF_SIZE/(sizeof (char *))];
int h_error=0;
#ifdef __GLIBC__
- gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error);
+ gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &hp, &h_error);
#else
- hp = gethostbyname_r(hostname, &res, buf, sizeof(buf), &h_error);
+ hp = gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &h_error);
#endif
if (hp) {
#ifdef __GLIBC__
gethostbyaddr_r(hp->h_addr, hp->h_length, AF_INET,
- &res2, buf2, sizeof(buf2), &hp, &h_error);
+ &res2, (char*)buf2, sizeof(buf2), &hp, &h_error);
#else
hp = gethostbyaddr_r(hp->h_addr, hp->h_length, AF_INET,
- &res2, buf2, sizeof(buf2), &h_error);
+ &res2, (char*)buf2, sizeof(buf2), &h_error);
#endif
if (hp) {
/*
@@ -136,7 +138,9 @@
const char *hostname;
jobjectArray ret = 0;
struct hostent res, *hp = 0;
- char buf[HENT_BUF_SIZE];
+ // this buffer must be pointer-aligned so is declared
+ // with pointer type
+ char *buf[HENT_BUF_SIZE/(sizeof (char *))];
/* temporary buffer, on the off chance we need to expand */
char *tmp = NULL;
@@ -176,9 +180,9 @@
/* Try once, with our static buffer. */
#ifdef __GLIBC__
- gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error);
+ gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &hp, &h_error);
#else
- hp = gethostbyname_r(hostname, &res, buf, sizeof(buf), &h_error);
+ hp = gethostbyname_r(hostname, &res, (char*)buf, sizeof(buf), &h_error);
#endif
/* With the re-entrant system calls, it's possible that the buffer
@@ -251,7 +255,9 @@
jstring ret = NULL;
jint addr;
struct hostent hent, *hp = 0;
- char buf[HENT_BUF_SIZE];
+ // this buffer must be pointer-aligned so is declared
+ // with pointer type
+ char *buf[HENT_BUF_SIZE/(sizeof (char *))];
int h_error = 0;
char *tmp = NULL;
@@ -273,10 +279,10 @@
addr = htonl(addr);
#ifdef __GLIBC__
gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET, &hent,
- buf, sizeof(buf), &hp, &h_error);
+ (char*)buf, sizeof(buf), &hp, &h_error);
#else
hp = gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET, &hent,
- buf, sizeof(buf), &h_error);
+ (char*)buf, sizeof(buf), &h_error);
#endif
/* With the re-entrant system calls, it's possible that the buffer
* we pass to it is not large enough to hold an exceptionally
--- a/jdk/src/solaris/native/java/net/NetworkInterface.c Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/native/java/net/NetworkInterface.c Mon Mar 07 14:48:27 2011 -0800
@@ -45,7 +45,6 @@
#ifdef __linux__
#include <sys/ioctl.h>
#include <bits/ioctls.h>
-#include <linux/sockios.h>
#include <sys/utsname.h>
#include <stdio.h>
#endif
@@ -1100,7 +1099,7 @@
#ifdef AF_INET6
static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
FILE *f;
- char addr6[40], devname[20];
+ char addr6[40], devname[21];
char addr6p[8][5];
int plen, scope, dad_status, if_idx;
uint8_t ipv6addr[16];
--- a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c Mon Mar 07 14:48:27 2011 -0800
@@ -34,8 +34,8 @@
#include <fcntl.h>
#endif
#ifdef __linux__
-#include <linux/unistd.h>
-#include <linux/sysctl.h>
+#include <unistd.h>
+#include <sys/sysctl.h>
#include <sys/utsname.h>
#include <netinet/ip.h>
--- a/jdk/src/solaris/native/java/net/PlainSocketImpl.c Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/native/java/net/PlainSocketImpl.c Mon Mar 07 14:48:27 2011 -0800
@@ -42,8 +42,8 @@
#include <fcntl.h>
#endif
#ifdef __linux__
-#include <linux/unistd.h>
-#include <linux/sysctl.h>
+#include <unistd.h>
+#include <sys/sysctl.h>
#endif
#include "jvm.h"
--- a/jdk/src/solaris/native/java/net/linux_close.c Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/native/java/net/linux_close.c Mon Mar 07 14:48:27 2011 -0800
@@ -112,7 +112,7 @@
*/
static inline fdEntry_t *getFdEntry(int fd)
{
- if (fd < 0 || fd > fdCount) {
+ if (fd < 0 || fd >= fdCount) {
return NULL;
}
return &fdTable[fd];
--- a/jdk/src/solaris/native/java/net/net_util_md.c Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/solaris/native/java/net/net_util_md.c Mon Mar 07 14:48:27 2011 -0800
@@ -608,7 +608,7 @@
{
/* now find the scope_id for "lo" */
- char devname[20];
+ char devname[21];
char addr6p[8][5];
int plen, scope, dad_status, if_idx;
@@ -651,7 +651,7 @@
static void initLocalIfs () {
FILE *f;
unsigned char staddr [16];
- char ifname [32];
+ char ifname [33];
struct localinterface *lif=0;
int index, x1, x2, x3;
unsigned int u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,ua,ub,uc,ud,ue,uf;
@@ -660,7 +660,7 @@
return ;
}
while (fscanf (f, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x "
- "%d %x %x %x %s",&u0,&u1,&u2,&u3,&u4,&u5,&u6,&u7,
+ "%d %x %x %x %32s",&u0,&u1,&u2,&u3,&u4,&u5,&u6,&u7,
&u8,&u9,&ua,&ub,&uc,&ud,&ue,&uf,
&index, &x1, &x2, &x3, ifname) == 21) {
staddr[0] = (unsigned char)u0;
@@ -1102,7 +1102,7 @@
* index.
*/
if (match) {
- char devname[20];
+ char devname[21];
char addr6p[8][5];
int plen, scope, dad_status, if_idx;
--- a/jdk/src/windows/classes/sun/nio/ch/PendingIoCache.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/windows/classes/sun/nio/ch/PendingIoCache.java Mon Mar 07 14:48:27 2011 -0800
@@ -110,8 +110,7 @@
if (closed)
return;
- // handle the case that where there are I/O operations that have
- // not completed.
+ // handle case where I/O operations that have not completed.
if (!pendingIoMap.isEmpty())
clearPendingIoMap();
@@ -132,7 +131,9 @@
closePending = true;
try {
this.wait(50);
- } catch (InterruptedException x) { }
+ } catch (InterruptedException x) {
+ Thread.currentThread().interrupt();
+ }
closePending = false;
if (pendingIoMap.isEmpty())
return;
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java Mon Mar 07 14:48:27 2011 -0800
@@ -439,6 +439,7 @@
address = ((DirectBuffer)buf).address();
}
+ boolean pending = false;
try {
begin();
@@ -449,6 +450,7 @@
n = readFile(handle, address, rem, position, overlapped);
if (n == IOStatus.UNAVAILABLE) {
// I/O is pending
+ pending = true;
return;
} else if (n == IOStatus.EOF) {
result.setResult(n);
@@ -460,14 +462,15 @@
// failed to initiate read
result.setFailure(toIOException(x));
} finally {
+ if (!pending) {
+ // release resources
+ if (overlapped != 0L)
+ ioCache.remove(overlapped);
+ releaseBufferIfSubstituted();
+ }
end();
}
- // release resources
- if (overlapped != 0L)
- ioCache.remove(overlapped);
- releaseBufferIfSubstituted();
-
// invoke completion handler
Invoker.invoke(result);
}
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java Mon Mar 07 14:48:27 2011 -0800
@@ -239,14 +239,14 @@
result.setResult(null);
}
} catch (Throwable x) {
+ if (overlapped != 0L)
+ ioCache.remove(overlapped);
exc = x;
} finally {
end();
}
if (exc != null) {
- if (overlapped != 0L)
- ioCache.remove(overlapped);
closeChannel();
result.setFailure(toIOException(exc));
}
--- a/jdk/src/windows/classes/sun/nio/fs/WindowsFileStore.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/src/windows/classes/sun/nio/fs/WindowsFileStore.java Mon Mar 07 14:48:27 2011 -0800
@@ -201,13 +201,12 @@
if (!(ob instanceof WindowsFileStore))
return false;
WindowsFileStore other = (WindowsFileStore)ob;
- return this.volInfo.volumeSerialNumber() == other.volInfo.volumeSerialNumber();
+ return root.equals(other.root);
}
@Override
public int hashCode() {
- // reveals VSN without permission check - okay?
- return volInfo.volumeSerialNumber();
+ return root.hashCode();
}
@Override
--- a/jdk/test/ProblemList.txt Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/ProblemList.txt Mon Mar 07 14:48:27 2011 -0800
@@ -380,30 +380,9 @@
# jdk_nio
-# 6944810
-java/nio/channels/FileChannel/ReleaseOnCloseDeadlock.java windows-all
-
# 6963118
java/nio/channels/Selector/Wakeup.java windows-all
-# The asynchronous I/O implementation on Windows requires Windows XP or newer.
-# We can remove the following once all Windows 2000 machines have been
-# decommissioned.
-java/nio/channels/AsynchronousChannelGroup/Basic.java windows-5.0
-java/nio/channels/AsynchronousChannelGroup/GroupOfOne.java windows-5.0
-java/nio/channels/AsynchronousChannelGroup/Identity.java windows-5.0
-java/nio/channels/AsynchronousChannelGroup/Restart.java windows-5.0
-java/nio/channels/AsynchronousChannelGroup/Unbounded.java windows-5.0
-java/nio/channels/AsynchronousDatagramChannel/Basic.java windows-5.0
-java/nio/channels/AsynchronousFileChannel/Lock.java windows-5.0
-java/nio/channels/AsynchronousServerSocketChannel/Basic.java windows-5.0
-java/nio/channels/AsynchronousServerSocketChannel/WithSecurityManager.java windows-5.0
-java/nio/channels/AsynchronousSocketChannel/Basic.java windows-5.0
-java/nio/channels/AsynchronousSocketChannel/DieBeforeComplete.java windows-5.0
-java/nio/channels/AsynchronousSocketChannel/Leaky.java windows-5.0
-java/nio/channels/AsynchronousSocketChannel/StressLoopback.java windows-5.0
-java/nio/channels/Channels/Basic2.java windows-5.0
-
# 6959891
com/sun/nio/sctp/SctpChannel/SocketOptionTests.java
@@ -625,9 +604,6 @@
# Timeout on solaris-sparcv9 or exception thrown
com/sun/crypto/provider/Cipher/RSA/TestOAEP_KAT.java solaris-all
-# File 6535697.test input stream left open? windows samevm
-java/security/cert/CertificateFactory/openssl/OpenSSLCert.java generic-all
-
# Leaving file open: SerialVersion.current, windows samevm
java/security/BasicPermission/SerialVersion.java generic-all
@@ -717,6 +693,7 @@
# Filed 6933803
java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java generic-all
+# Filed 7022325
# Fails with assertion error on windows
# 11 separate stacktraces created... file reuse problem?
java/util/zip/ZipFile/ReadLongZipFileName.java generic-all
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java Mon Mar 07 14:48:27 2011 -0800
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 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
+ * 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 6748156
+ * @summary add an new JNDI property to control the boolean flag WaitForReply
+ */
+
+import java.net.Socket;
+import java.net.ServerSocket;
+import java.io.*;
+import javax.naming.*;
+import javax.naming.directory.*;
+import java.util.Hashtable;
+
+public class NoWaitForReplyTest {
+
+ public static void main(String[] args) throws Exception {
+
+ boolean passed = false;
+
+ // start the LDAP server
+ DummyServer ldapServer = new DummyServer();
+ ldapServer.start();
+
+ // Set up the environment for creating the initial context
+ Hashtable env = new Hashtable(11);
+ env.put(Context.PROVIDER_URL, "ldap://localhost:" +
+ ldapServer.getPortNumber());
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "com.sun.jndi.ldap.LdapCtxFactory");
+
+ // Wait up to 10 seconds for a response from the LDAP server
+ env.put("com.sun.jndi.ldap.read.timeout", "10000");
+
+ // Don't wait until the first search reply is received
+ env.put("com.sun.jndi.ldap.search.waitForReply", "false");
+
+ // Send the LDAP search request without first authenticating (no bind)
+ env.put("java.naming.ldap.version", "3");
+
+
+ try {
+
+ // Create initial context
+ System.out.println("Client: connecting to the server");
+ DirContext ctx = new InitialDirContext(env);
+
+ SearchControls scl = new SearchControls();
+ scl.setSearchScope(SearchControls.SUBTREE_SCOPE);
+ System.out.println("Client: performing search");
+ NamingEnumeration answer =
+ ctx.search("ou=People,o=JNDITutorial", "(objectClass=*)", scl);
+
+ // Server will never reply: either we waited in the call above until
+ // the timeout (fail) or we did not wait and reached here (pass).
+ passed = true;
+ System.out.println("Client: did not wait until first reply");
+
+ // Close the context when we're done
+ ctx.close();
+
+ } catch (NamingException e) {
+ // timeout (ignore)
+ }
+ ldapServer.interrupt();
+
+ if (!passed) {
+ throw new Exception(
+ "Test FAILED: should not have waited until first search reply");
+ }
+ System.out.println("Test PASSED");
+ }
+
+ static class DummyServer extends Thread {
+
+ private final ServerSocket serverSocket;
+
+ DummyServer() throws IOException {
+ this.serverSocket = new ServerSocket(0);
+ System.out.println("Server: listening on port " + serverSocket.getLocalPort());
+ }
+
+ public int getPortNumber() {
+ return serverSocket.getLocalPort();
+ }
+
+ public void run() {
+ try (Socket socket = serverSocket.accept()) {
+ System.out.println("Server: accepted a connection");
+ InputStream in = socket.getInputStream();
+
+ while (!isInterrupted()) {
+ in.skip(in.available());
+ }
+
+ } catch (Exception e) {
+ // ignore
+
+ } finally {
+ System.out.println("Server: shutting down");
+ try {
+ serverSocket.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+}
--- a/jdk/test/java/io/File/SetLastModified.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/io/File/SetLastModified.java Mon Mar 07 14:48:27 2011 -0800
@@ -105,9 +105,9 @@
System.getProperty("os.name").startsWith("Windows") ? 0L : 3L*G;
long pos = 0L;
while (pos <= MAX_POSITION) {
- FileChannel fc = new FileOutputStream(f).getChannel();
- fc.position(pos).write(ByteBuffer.wrap("x".getBytes()));
- fc.close();
+ try (FileChannel fc = new FileOutputStream(f).getChannel()) {
+ fc.position(pos).write(ByteBuffer.wrap("x".getBytes()));
+ }
ot = f.lastModified();
System.out.format("check with file size: %d\n", f.length());
if (!f.setLastModified(nt))
--- a/jdk/test/java/io/FileOutputStream/AtomicAppend.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/io/FileOutputStream/AtomicAppend.java Mon Mar 07 14:48:27 2011 -0800
@@ -47,12 +47,12 @@
for (int i = 0; i < nThreads; i++)
es.execute(new Runnable() { public void run() {
try {
- FileOutputStream s = new FileOutputStream(file, true);
- for (int j = 0; j < 1000; j++) {
- s.write((int) 'x');
- s.flush();
+ try (FileOutputStream s = new FileOutputStream(file, true)) {
+ for (int j = 0; j < 1000; j++) {
+ s.write((int) 'x');
+ s.flush();
+ }
}
- s.close();
} catch (Throwable t) { unexpected(t); }}});
es.shutdown();
es.awaitTermination(10L, TimeUnit.MINUTES);
--- a/jdk/test/java/io/OutputStreamWriter/Encode.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/io/OutputStreamWriter/Encode.java Mon Mar 07 14:48:27 2011 -0800
@@ -35,8 +35,9 @@
new Encode();
}
+ final ServerSocket ss = new ServerSocket(0);
+
Encode() throws Exception {
- ss = new ServerSocket(0);
(new Thread(this)).start();
String toEncode = "\uD800\uDC00 \uD801\uDC01 ";
String enc1 = URLEncoder.encode(toEncode, "UTF-8");
@@ -47,27 +48,31 @@
"/missing.nothtml";
HttpURLConnection uc = (HttpURLConnection)new URL(url).openConnection();
uc.connect();
- String enc2 = URLEncoder.encode(toEncode, "UTF-8");
- if (!enc1.equals(enc2))
- throw new RuntimeException("test failed");
- uc.disconnect();
+ try {
+ String enc2 = URLEncoder.encode(toEncode, "UTF-8");
+ if (!enc1.equals(enc2)) {
+ System.out.println("test failed");
+ throw new RuntimeException("test failed");
+ }
+ } finally {
+ uc.disconnect();
+ }
}
- ServerSocket ss;
-
public void run() {
- try {
- Socket s = ss.accept();
- BufferedReader in = new BufferedReader(
- new InputStreamReader(s.getInputStream()));
+ try (ServerSocket serv = ss;
+ Socket s = serv.accept();
+ BufferedReader in =
+ new BufferedReader(new InputStreamReader(s.getInputStream())))
+ {
String req = in.readLine();
- PrintStream out = new PrintStream(new BufferedOutputStream(
- s.getOutputStream()));
- out.print("HTTP/1.1 403 Forbidden\r\n");
- out.print("\r\n");
- out.flush();
- s.close();
- ss.close();
+ try (OutputStream os = s.getOutputStream();
+ BufferedOutputStream bos = new BufferedOutputStream(os);
+ PrintStream out = new PrintStream(bos))
+ {
+ out.print("HTTP/1.1 403 Forbidden\r\n");
+ out.print("\r\n");
+ }
} catch (Exception e) {
e.printStackTrace();
}
--- a/jdk/test/java/io/PrintStream/EncodingConstructor.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/io/PrintStream/EncodingConstructor.java Mon Mar 07 14:48:27 2011 -0800
@@ -34,11 +34,11 @@
public static void main(String args[]) throws Exception {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(bo, false, "UTF-8");
String s = "xyzzy";
int n = s.length();
- ps.print(s);
- ps.close();
+ try (PrintStream ps = new PrintStream(bo, false, "UTF-8")) {
+ ps.print(s);
+ }
byte[] ba = bo.toByteArray();
if (ba.length != n)
throw new Exception("Length mismatch: " + n + " " + ba.length);
--- a/jdk/test/java/io/PrintStream/FailingConstructors.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/io/PrintStream/FailingConstructors.java Mon Mar 07 14:48:27 2011 -0800
@@ -35,6 +35,8 @@
import java.io.IOException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
+import java.nio.file.Files;
+import java.nio.file.Path;
public class FailingConstructors {
static final String fileName = "FailingConstructorsTest";
@@ -45,14 +47,13 @@
test(false, new File(fileName));
/* create the file and write its contents */
- File file = File.createTempFile(fileName, null);
- file.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(FILE_CONTENTS.getBytes());
- fos.close();
-
- test(true, file);
- file.delete();
+ Path path = Files.createTempFile(fileName, null);
+ try {
+ Files.write(path, FILE_CONTENTS.getBytes());
+ test(true, path.toFile());
+ } finally {
+ Files.delete(path);
+ }
}
private static void test(boolean exists, File file) throws Throwable {
--- a/jdk/test/java/io/Serializable/evolution/RenamePackage/install/SerialDriver.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/io/Serializable/evolution/RenamePackage/install/SerialDriver.java Mon Mar 07 14:48:27 2011 -0800
@@ -27,7 +27,7 @@
* @build install/SerialDriver.java test/SerialDriver.java extension/ExtendedObjectInputStream.java
* @summary Enable resolveClass() to accommodate package renaming.
* This fix enables one to implement a resolveClass method that maps a
- * Serialiazable class within a serialization stream to the same class
+ * Serializable class within a serialization stream to the same class
* in a different package within the JVM runtime. See run shell script
* for instructions on how to run this test.
*/
@@ -86,16 +86,15 @@
File f = new File("stream.ser");
if (serialize) {
// Serialize the subclass
- try {
- FileOutputStream fo = new FileOutputStream(f);
- ObjectOutputStream so = new ObjectOutputStream(fo);
+ try (FileOutputStream fo = new FileOutputStream(f);
+ ObjectOutputStream so = new ObjectOutputStream(fo))
+ {
so.writeObject(obj);
/* Skip arrays since they do not work with rename yet.
The serialVersionUID changes due to the name change
and there is no way to set the serialVersionUID for an
array. */
so.writeObject(array);
- so.flush();
} catch (Exception e) {
System.out.println(e);
throw e;
@@ -103,16 +102,14 @@
}
if (deserialize) {
// Deserialize the subclass
- try {
- FileInputStream fi = new FileInputStream(f);
- ExtendedObjectInputStream si =
- new ExtendedObjectInputStream(fi);
+ try (FileInputStream fi = new FileInputStream(f);
+ ExtendedObjectInputStream si = new ExtendedObjectInputStream(fi))
+ {
si.addRenamedClassName("test.SerialDriver", "install.SerialDriver");
si.addRenamedClassName("[Ltest.SerialDriver;",
"[Linstall.SerialDriver");
obj = (SerialDriver) si.readObject();
array = (SerialDriver[]) si.readObject();
- si.close();
} catch (Exception e) {
System.out.println(e);
throw e;
--- a/jdk/test/java/io/Serializable/evolution/RenamePackage/test/SerialDriver.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/io/Serializable/evolution/RenamePackage/test/SerialDriver.java Mon Mar 07 14:48:27 2011 -0800
@@ -27,7 +27,7 @@
* @build install/SerialDriver.java test/SerialDriver.java extension/ExtendedObjectInputStream.java
* @summary Enable resolveClass() to accommodate package renaming.
* This fix enables one to implement a resolveClass method that maps a
- * Serialiazable class within a serialization stream to the same class
+ * Serializable class within a serialization stream to the same class
* in a different package within the JVM runtime. See run shell script
* for instructions on how to run this test.
*/
@@ -83,14 +83,13 @@
File f = new File("stream.ser");
if (serialize) {
// Serialize the subclass
- try {
- FileOutputStream fo = new FileOutputStream(f);
- ObjectOutputStream so = new ObjectOutputStream(fo);
+ try (FileOutputStream fo = new FileOutputStream(f);
+ ObjectOutputStream so = new ObjectOutputStream(fo))
+ {
so.writeObject(obj);
/* Comment out since renaming arrays does not work
since it changes the serialVersionUID. */
so.writeObject(array);
- so.flush();
} catch (Exception e) {
System.out.println(e);
throw e;
@@ -98,16 +97,15 @@
}
if (deserialize) {
// Deserialize the subclass
- try {
- FileInputStream fi = new FileInputStream(f);
- ExtendedObjectInputStream si = new ExtendedObjectInputStream(fi);
+ try (FileInputStream fi = new FileInputStream(f);
+ ExtendedObjectInputStream si = new ExtendedObjectInputStream(fi))
+ {
si.addRenamedClassName("install.SerialDriver",
"test.SerialDriver");
si.addRenamedClassName("[Linstall.SerialDriver;",
"[Ltest.SerialDriver");
obj = (SerialDriver) si.readObject();
array = (SerialDriver[]) si.readObject();
- si.close();
} catch (Exception e) {
System.out.println(e);
throw e;
--- a/jdk/test/java/lang/Character/CheckScript.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/lang/Character/CheckScript.java Mon Mar 07 14:48:27 2011 -0800
@@ -12,40 +12,43 @@
public class CheckScript {
- public static void main(String[] args) throws Exception {
-
- BufferedReader sbfr = null;
+ static BufferedReader open(String[] args) throws FileNotFoundException {
if (args.length == 0) {
- sbfr = new BufferedReader(new FileReader(new File(System.getProperty("test.src", "."), "Scripts.txt")));
+ return new BufferedReader(new FileReader(new File(System.getProperty("test.src", "."), "Scripts.txt")));
} else if (args.length == 1) {
- sbfr = new BufferedReader(new FileReader(args[0]));
+ return new BufferedReader(new FileReader(args[0]));
} else {
System.out.println("java CharacterScript Scripts.txt");
throw new RuntimeException("Datafile name should be specified.");
}
+ }
+
+ public static void main(String[] args) throws Exception {
+
Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s+;\\s+(\\w+)\\s+#.*").matcher("");
String line = null;
HashMap<String,ArrayList<Integer>> scripts = new HashMap<>();
- while ((line = sbfr.readLine()) != null) {
- if (line.length() <= 1 || line.charAt(0) == '#') {
- continue;
- }
- m.reset(line);
- if (m.matches()) {
- int start = Integer.parseInt(m.group(1), 16);
- int end = (m.group(2)==null)?start
- :Integer.parseInt(m.group(2), 16);
- String name = m.group(3).toLowerCase(Locale.ENGLISH);
- ArrayList<Integer> ranges = scripts.get(name);
- if (ranges == null) {
- ranges = new ArrayList<Integer>();
- scripts.put(name, ranges);
+ try (BufferedReader sbfr = open(args)) {
+ while ((line = sbfr.readLine()) != null) {
+ if (line.length() <= 1 || line.charAt(0) == '#') {
+ continue;
}
- ranges.add(start);
- ranges.add(end);
+ m.reset(line);
+ if (m.matches()) {
+ int start = Integer.parseInt(m.group(1), 16);
+ int end = (m.group(2)==null)?start
+ :Integer.parseInt(m.group(2), 16);
+ String name = m.group(3).toLowerCase(Locale.ENGLISH);
+ ArrayList<Integer> ranges = scripts.get(name);
+ if (ranges == null) {
+ ranges = new ArrayList<Integer>();
+ scripts.put(name, ranges);
+ }
+ ranges.add(start);
+ ranges.add(end);
+ }
}
}
- sbfr.close();
// check all defined ranges
Integer[] ZEROSIZEARRAY = new Integer[0];
for (String name : scripts.keySet()) {
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java Mon Mar 07 14:48:27 2011 -0800
@@ -26,7 +26,7 @@
* @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
* 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
* 6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
- * 4947220
+ * 4947220 7018606
* @summary Basic tests for Process and Environment Variable code
* @run main/othervm/timeout=300 Basic
* @author Martin Buchholz
@@ -47,6 +47,9 @@
public class Basic {
+ /* used for Windows only */
+ static final String systemRoot = System.getenv("SystemRoot");
+
private static String commandOutput(Reader r) throws Throwable {
StringBuilder sb = new StringBuilder();
int c;
@@ -1073,7 +1076,11 @@
try {
ProcessBuilder pb = new ProcessBuilder();
pb.environment().clear();
- equal(getenvInChild(pb), "");
+ String expected = Windows.is() ? "SystemRoot="+systemRoot+",": "";
+ if (Windows.is()) {
+ pb.environment().put("SystemRoot", systemRoot);
+ }
+ equal(getenvInChild(pb), expected);
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
@@ -1561,13 +1568,21 @@
List<String> childArgs = new ArrayList<String>(javaChildArgs);
childArgs.add("System.getenv()");
String[] cmdp = childArgs.toArray(new String[childArgs.size()]);
- String[] envp = {"=ExitValue=3", "=C:=\\"};
+ String[] envp;
+ String[] envpWin = {"=ExitValue=3", "=C:=\\", "SystemRoot="+systemRoot};
+ String[] envpOth = {"=ExitValue=3", "=C:=\\"};
+ if (Windows.is()) {
+ envp = envpWin;
+ } else {
+ envp = envpOth;
+ }
Process p = Runtime.getRuntime().exec(cmdp, envp);
- String expected = Windows.is() ? "=C:=\\,=ExitValue=3," : "=C:=\\,";
+ String expected = Windows.is() ? "=C:=\\,SystemRoot="+systemRoot+",=ExitValue=3," : "=C:=\\,";
equal(commandOutput(p), expected);
if (Windows.is()) {
ProcessBuilder pb = new ProcessBuilder(childArgs);
pb.environment().clear();
+ pb.environment().put("SystemRoot", systemRoot);
pb.environment().put("=ExitValue", "3");
pb.environment().put("=C:", "\\");
equal(commandOutput(pb), expected);
@@ -1591,10 +1606,18 @@
List<String> childArgs = new ArrayList<String>(javaChildArgs);
childArgs.add("System.getenv()");
String[] cmdp = childArgs.toArray(new String[childArgs.size()]);
- String[] envp = {"LC_ALL=C\u0000\u0000", // Yuck!
+ String[] envpWin = {"SystemRoot="+systemRoot, "LC_ALL=C\u0000\u0000", // Yuck!
+ "FO\u0000=B\u0000R"};
+ String[] envpOth = {"LC_ALL=C\u0000\u0000", // Yuck!
"FO\u0000=B\u0000R"};
+ String[] envp;
+ if (Windows.is()) {
+ envp = envpWin;
+ } else {
+ envp = envpOth;
+ }
Process p = Runtime.getRuntime().exec(cmdp, envp);
- check(commandOutput(p).equals("LC_ALL=C,"),
+ check(commandOutput(p).equals(Windows.is() ? "SystemRoot="+systemRoot+",LC_ALL=C," : "LC_ALL=C,"),
"Incorrect handling of envstrings containing NULs");
} catch (Throwable t) { unexpected(t); }
@@ -2144,6 +2167,7 @@
static void equal(Object x, Object y) {
if (x == null ? y == null : x.equals(y)) pass();
else fail(x + " not equal to " + y);}
+
public static void main(String[] args) throws Throwable {
try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
--- a/jdk/test/java/lang/Runtime/shutdown/ShutdownHooks.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/lang/Runtime/shutdown/ShutdownHooks.java Mon Mar 07 14:48:27 2011 -0800
@@ -43,9 +43,9 @@
file = new File(dir, args[1]);
// write to file
System.out.println("writing to "+ file);
- PrintWriter pw = new PrintWriter(file);
- pw.println("Shutdown begins");
- pw.close();
+ try (PrintWriter pw = new PrintWriter(file)) {
+ pw.println("Shutdown begins");
+ }
}
public static class Cleaner extends Thread {
@@ -56,10 +56,8 @@
// register the DeleteOnExitHook while the application
// shutdown hook is running
file.deleteOnExit();
- try {
- PrintWriter pw = new PrintWriter(file);
+ try (PrintWriter pw = new PrintWriter(file)) {
pw.println("file is being deleted");
- pw.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
--- a/jdk/test/java/lang/Thread/StartOOMTest.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/lang/Thread/StartOOMTest.java Mon Mar 07 14:48:27 2011 -0800
@@ -22,11 +22,14 @@
*/
/*
- * @test
- * @bug 6379235
- * @ignore until 6721694 is fixed
- * @run main/othervm -server -Xmx32m -Xms32m -Xss256m StartOOMTest
- * @summary ThreadGroup accounting mistake possible with failure of Thread.start()
+ * This test is relatively useful for verifying 6379235, but
+ * is too resource intensive, especially on 64 bit systems,
+ * to be run automatically, see 6721694.
+ *
+ * When run it should be typically be run with the server vm
+ * and a relatively small java heap, and a large stack size
+ * ( to provoke the OOM quicker ).
+ * java -server -Xmx32m -Xms32m -Xss256m StartOOMTest
*/
import java.util.*;
--- a/jdk/test/java/lang/instrument/BootClassPath/Setup.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/lang/instrument/BootClassPath/Setup.java Mon Mar 07 14:48:27 2011 -0800
@@ -62,31 +62,33 @@
* Create manifest file with Boot-Class-Path encoding the
* sub-directory name.
*/
- FileOutputStream out = new FileOutputStream(manifestFile);
- out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
+ try (FileOutputStream out = new FileOutputStream(manifestFile)) {
+ out.write("Manifest-Version: 1.0\n".getBytes("UTF-8"));
- byte[] premainBytes = ("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");
- out.write(premainBytes);
+ byte[] premainBytes =
+ ("Premain-Class: " + premainClass + "\n").getBytes("UTF-8");
+ out.write(premainBytes);
- out.write( "Boot-Class-Path: ".getBytes("UTF-8") );
+ out.write( "Boot-Class-Path: ".getBytes("UTF-8") );
- byte[] value = bootClassPath.getBytes("UTF-8");
- for (int i=0; i<value.length; i++) {
- int v = (int)value[i];
- if (v < 0) v += 256;
- byte[] escaped = ("%" + Integer.toHexString(v)).getBytes("UTF-8");
- out.write(escaped);
+ byte[] value = bootClassPath.getBytes("UTF-8");
+ for (int i=0; i<value.length; i++) {
+ int v = (int)value[i];
+ if (v < 0) v += 256;
+ byte[] escaped =
+ ("%" + Integer.toHexString(v)).getBytes("UTF-8");
+ out.write(escaped);
+ }
+ out.write( "\n\n".getBytes("UTF-8") );
}
- out.write( "\n\n".getBytes("UTF-8") );
- out.close();
/*
* Write the name of the boot dir to "boot.dir"
*/
f = new File(workDir + fileSeparator + "boot.dir");
- out = new FileOutputStream(f);
- out.write(bootDir.getBytes(defaultEncoding));
- out.close();
+ try (FileOutputStream out = new FileOutputStream(f)) {
+ out.write(bootDir.getBytes(defaultEncoding));
+ }
}
/* ported from test/sun/tools/launcher/UnicodeTest.java */
--- a/jdk/test/java/lang/instrument/ilib/Inject.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/lang/instrument/ilib/Inject.java Mon Mar 07 14:48:27 2011 -0800
@@ -118,23 +118,24 @@
}
void dump(File outDir, String filename) throws IOException {
- FileOutputStream fileOut = new FileOutputStream(new File(outDir, filename));
- DataOutputStream dataOut = new DataOutputStream(fileOut);
-
- String currentClassName = null;
+ try (FileOutputStream fileOut =
+ new FileOutputStream(new File(outDir, filename));
+ DataOutputStream dataOut = new DataOutputStream(fileOut))
+ {
+ String currentClassName = null;
- dataOut.writeInt(infoList.size());
- for (Iterator<Info> it = infoList.iterator(); it.hasNext(); ) {
- Info info = it.next();
- if (!info.className.equals(currentClassName)) {
- dataOut.writeInt(123456); // class name marker
- currentClassName = info.className;
- dataOut.writeUTF(currentClassName);
+ dataOut.writeInt(infoList.size());
+ for (Iterator<Info> it = infoList.iterator(); it.hasNext(); ) {
+ Info info = it.next();
+ if (!info.className.equals(currentClassName)) {
+ dataOut.writeInt(123456); // class name marker
+ currentClassName = info.className;
+ dataOut.writeUTF(currentClassName);
+ }
+ dataOut.writeInt(info.location);
+ dataOut.writeUTF(info.methodName);
}
- dataOut.writeInt(info.location);
- dataOut.writeUTF(info.methodName);
}
- dataOut.close();
}
public byte[] bytecodes(String className, String methodName, int location) {
--- a/jdk/test/java/math/BigInteger/BigIntegerTest.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/math/BigInteger/BigIntegerTest.java Mon Mar 07 14:48:27 2011 -0800
@@ -645,26 +645,17 @@
BigInteger b2 = null;
File f = new File("serialtest");
- FileOutputStream fos = new FileOutputStream(f);
- try {
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- try {
+
+ try (FileOutputStream fos = new FileOutputStream(f)) {
+ try (ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject(b1);
oos.flush();
- } finally {
- oos.close();
}
- FileInputStream fis = new FileInputStream(f);
- try {
- ObjectInputStream ois = new ObjectInputStream(fis);
- try {
- b2 = (BigInteger)ois.readObject();
- } finally {
- ois.close();
- }
- } finally {
- fis.close();
+ try (FileInputStream fis = new FileInputStream(f);
+ ObjectInputStream ois = new ObjectInputStream(fis))
+ {
+ b2 = (BigInteger)ois.readObject();
}
if (!b1.equals(b2) ||
@@ -673,8 +664,6 @@
System.err.println("Serialized failed for hex " +
b1.toString(16));
}
- } finally {
- fos.close();
}
f.delete();
}
@@ -683,29 +672,17 @@
BigInteger b1 = fetchNumber(rnd.nextInt(100));
BigInteger b2 = null;
File f = new File("serialtest");
- FileOutputStream fos = new FileOutputStream(f);
- try {
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- try {
+ try (FileOutputStream fos = new FileOutputStream(f)) {
+ try (ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject(b1);
oos.flush();
- } finally {
- oos.close();
}
- FileInputStream fis = new FileInputStream(f);
- try {
- ObjectInputStream ois = new ObjectInputStream(fis);
- try {
- b2 = (BigInteger)ois.readObject();
- } finally {
- ois.close();
- }
- } finally {
- fis.close();
+ try (FileInputStream fis = new FileInputStream(f);
+ ObjectInputStream ois = new ObjectInputStream(fis))
+ {
+ b2 = (BigInteger)ois.readObject();
}
- } finally {
- fos.close();
}
if (!b1.equals(b2) ||
--- a/jdk/test/java/net/URLConnection/RedirectLimit.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/net/URLConnection/RedirectLimit.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -36,105 +36,81 @@
import java.net.*;
class RedirLimitServer extends Thread {
+ static final int TIMEOUT = 10 * 1000;
+ static final int NUM_REDIRECTS = 9;
- ServerSocket s;
- Socket s1;
- InputStream is;
- OutputStream os;
- int port;
- int nredirects = 9;
-
- String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
+ static final String reply1 = "HTTP/1.1 307 Temporary Redirect\r\n" +
"Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
"Server: Apache/1.3.14 (Unix)\r\n" +
"Location: http://localhost:";
- String reply2 = ".html\r\n" +
+ static final String reply2 = ".html\r\n" +
"Connection: close\r\n" +
"Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
"<html>Hello</html>";
-
- RedirLimitServer (ServerSocket y) {
- s = y;
- port = s.getLocalPort();
- }
-
- String reply3 = "HTTP/1.1 200 Ok\r\n" +
+ static final String reply3 = "HTTP/1.1 200 Ok\r\n" +
"Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" +
"Server: Apache/1.3.14 (Unix)\r\n" +
"Connection: close\r\n" +
"Content-Type: text/html; charset=iso-8859-1\r\n\r\n" +
"World";
- public void run () {
+ final ServerSocket ss;
+ final int port;
+
+ RedirLimitServer(ServerSocket ss) {
+ this.ss = ss;
+ port = ss.getLocalPort();
+ }
+
+ public void run() {
try {
- s.setSoTimeout (2000);
- for (int i=0; i<nredirects; i++) {
- s1 = s.accept ();
- s1.setSoTimeout (2000);
- is = s1.getInputStream ();
- os = s1.getOutputStream ();
- is.read ();
- String reply = reply1 + port + "/redirect" + i + reply2;
- os.write (reply.getBytes());
- os.close();
+ ss.setSoTimeout(TIMEOUT);
+ for (int i=0; i<NUM_REDIRECTS; i++) {
+ try (Socket s = ss.accept()) {
+ s.setSoTimeout(TIMEOUT);
+ InputStream is = s.getInputStream();
+ OutputStream os = s.getOutputStream();
+ is.read();
+ String reply = reply1 + port + "/redirect" + i + reply2;
+ os.write(reply.getBytes());
+ }
}
- s1 = s.accept ();
- is = s1.getInputStream ();
- os = s1.getOutputStream ();
- is.read ();
- os.write (reply3.getBytes());
- os.close();
- }
- catch (Exception e) {
- /* Just need thread to terminate */
+ try (Socket s = ss.accept()) {
+ InputStream is = s.getInputStream();
+ OutputStream os = s.getOutputStream();
+ is.read();
+ os.write(reply3.getBytes());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
} finally {
- try { s.close(); } catch (IOException unused) {}
+ try { ss.close(); } catch (IOException unused) {}
}
}
};
-
public class RedirectLimit {
-
- public static final int DELAY = 10;
-
public static void main(String[] args) throws Exception {
- int nLoops = 1;
- int nSize = 10;
- int port, n =0;
- byte b[] = new byte[nSize];
- RedirLimitServer server;
- ServerSocket sock;
+ ServerSocket ss = new ServerSocket (0);
+ int port = ss.getLocalPort();
+ RedirLimitServer server = new RedirLimitServer(ss);
+ server.start();
+ InputStream in = null;
try {
- sock = new ServerSocket (0);
- port = sock.getLocalPort ();
- }
- catch (Exception e) {
- System.out.println ("Exception: " + e);
- return;
- }
-
- server = new RedirLimitServer(sock);
- server.start ();
-
- try {
-
- String s = "http://localhost:" + port;
- URL url = new URL(s);
+ URL url = new URL("http://localhost:" + port);
URLConnection conURL = url.openConnection();
conURL.setDoInput(true);
conURL.setAllowUserInteraction(false);
conURL.setUseCaches(false);
- InputStream in = conURL.getInputStream();
+ in = conURL.getInputStream();
if ((in.read() != (int)'W') || (in.read()!=(int)'o')) {
- throw new RuntimeException ("Unexpected string read");
+ throw new RuntimeException("Unexpected string read");
}
- }
- catch(IOException e) {
- throw new RuntimeException ("Exception caught " + e);
+ } finally {
+ if ( in != null ) { in.close(); }
}
}
}
--- a/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java Mon Mar 07 14:48:27 2011 -0800
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4607272 6842687 6878369
+ * @bug 4607272 6842687 6878369 6944810 7023403
* @summary Unit test for AsynchronousSocketChannel
* @run main/timeout=600 Basic
*/
--- a/jdk/test/java/nio/file/FileStore/Basic.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/nio/file/FileStore/Basic.java Mon Mar 07 14:48:27 2011 -0800
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887 6873621 6979526 7006126
+ * @bug 4313887 6873621 6979526 7006126 7020517
* @summary Unit test for java.nio.file.FileStore
* @library ..
*/
--- a/jdk/test/java/nio/file/Files/TemporaryFiles.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/nio/file/Files/TemporaryFiles.java Mon Mar 07 14:48:27 2011 -0800
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887 6838333 7006126
+ * @bug 4313887 6838333 7006126 7023034
* @summary Unit test for Files.createTempXXX
* @library ..
*/
@@ -167,5 +167,31 @@
testInvalidFileTemp("../blah", null);
testInvalidFileTemp("dir/blah", null);
testInvalidFileTemp("blah", ".dat/foo");
+
+ // nulls
+ try {
+ Files.createTempFile("blah", ".tmp", (FileAttribute<?>[])null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempFile("blah", ".tmp", new FileAttribute<?>[] { null });
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempDirectory("blah", (FileAttribute<?>[])null);
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempDirectory("blah", new FileAttribute<?>[] { null });
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempFile((Path)null, "blah", ".tmp");
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
+ try {
+ Files.createTempDirectory((Path)null, "blah");
+ throw new RuntimeException("NullPointerException expected");
+ } catch (NullPointerException ignore) { }
}
}
--- a/jdk/test/java/security/cert/CertificateFactory/openssl/OpenSSLCert.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/security/cert/CertificateFactory/openssl/OpenSSLCert.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -28,6 +28,8 @@
*/
import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.security.cert.CertificateFactory;
@@ -46,24 +48,20 @@
}
static void test(String... files) throws Exception {
- FileOutputStream fout = new FileOutputStream(OUTFILE);
- for (String file: files) {
- FileInputStream fin = new FileInputStream(
- new File(System.getProperty("test.src", "."), file));
- byte[] buffer = new byte[4096];
- while (true) {
- int len = fin.read(buffer);
- if (len < 0) break;
- fout.write(buffer, 0, len);
+ try (FileOutputStream fout = new FileOutputStream(OUTFILE)) {
+ String here = System.getProperty("test.src", "");
+ for (String file: files) {
+ Files.copy(Paths.get(here, file), fout);
}
- fin.close();
}
- fout.close();
- System.out.println("Testing " + Arrays.toString(files) + "...");
- if (CertificateFactory.getInstance("X509")
- .generateCertificates(new FileInputStream(OUTFILE))
- .size() != files.length) {
- throw new Exception("Not same number");
+ try (FileInputStream fin = new FileInputStream(OUTFILE)) {
+ System.out.println("Testing " + Arrays.toString(files) + "...");
+ if (CertificateFactory.getInstance("X509")
+ .generateCertificates(fin)
+ .size() != files.length) {
+ throw new Exception("Not same number");
+ }
}
+ Files.delete(Paths.get(OUTFILE));
}
}
--- a/jdk/test/java/util/Collection/MOAT.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/Collection/MOAT.java Mon Mar 07 14:48:27 2011 -0800
@@ -28,6 +28,8 @@
* 6431845 4802633 6570566 6570575 6570631 6570924 6691185 6691215
* @summary Run many tests on many Collection and Map implementations
* @author Martin Buchholz
+ * @run main MOAT
+ * @run main/othervm -XX:+AggressiveOpts MOAT
*/
/* Mother Of All (Collection) Tests
--- a/jdk/test/java/util/Currency/ValidateISO4217.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/Currency/ValidateISO4217.java Mon Mar 07 14:48:27 2011 -0800
@@ -111,57 +111,58 @@
static void test1() throws Exception {
- FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));
- BufferedReader in = new BufferedReader(fr);
- String line;
- SimpleDateFormat format = null;
+ try (FileReader fr = new FileReader(new File(System.getProperty("test.src", "."), datafile));
+ BufferedReader in = new BufferedReader(fr))
+ {
+ String line;
+ SimpleDateFormat format = null;
- while ((line = in.readLine()) != null) {
- if (line.length() == 0 || line.charAt(0) == '#') {
- continue;
- }
+ while ((line = in.readLine()) != null) {
+ if (line.length() == 0 || line.charAt(0) == '#') {
+ continue;
+ }
- StringTokenizer tokens = new StringTokenizer(line, "\t");
- String country = tokens.nextToken();
- if (country.length() != 2) {
- continue;
- }
+ StringTokenizer tokens = new StringTokenizer(line, "\t");
+ String country = tokens.nextToken();
+ if (country.length() != 2) {
+ continue;
+ }
- String currency;
- String numeric;
- String minorUnit;
- int tokensCount = tokens.countTokens();
- if (tokensCount < 3) {
- currency = "";
- numeric = "0";
- minorUnit = "0";
- } else {
- currency = tokens.nextToken();
- numeric = tokens.nextToken();
- minorUnit = tokens.nextToken();
- testCurrencies.add(Currency.getInstance(currency));
+ String currency;
+ String numeric;
+ String minorUnit;
+ int tokensCount = tokens.countTokens();
+ if (tokensCount < 3) {
+ currency = "";
+ numeric = "0";
+ minorUnit = "0";
+ } else {
+ currency = tokens.nextToken();
+ numeric = tokens.nextToken();
+ minorUnit = tokens.nextToken();
+ testCurrencies.add(Currency.getInstance(currency));
- // check for the cutover
- if (tokensCount > 3) {
- if (format == null) {
- format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
- format.setTimeZone(TimeZone.getTimeZone("GMT"));
- format.setLenient(false);
- }
- if (format.parse(tokens.nextToken()).getTime() <
- System.currentTimeMillis()) {
- currency = tokens.nextToken();
- numeric = tokens.nextToken();
- minorUnit = tokens.nextToken();
- testCurrencies.add(Currency.getInstance(currency));
+ // check for the cutover
+ if (tokensCount > 3) {
+ if (format == null) {
+ format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);
+ format.setTimeZone(TimeZone.getTimeZone("GMT"));
+ format.setLenient(false);
+ }
+ if (format.parse(tokens.nextToken()).getTime() <
+ System.currentTimeMillis()) {
+ currency = tokens.nextToken();
+ numeric = tokens.nextToken();
+ minorUnit = tokens.nextToken();
+ testCurrencies.add(Currency.getInstance(currency));
+ }
}
}
+ int index = toIndex(country);
+ testCountryCurrency(country, currency, Integer.parseInt(numeric),
+ Integer.parseInt(minorUnit), index);
}
- int index = toIndex(country);
- testCountryCurrency(country, currency, Integer.parseInt(numeric),
- Integer.parseInt(minorUnit), index);
}
- in.close();
for (int i = 0; i < additionalCodes.length; i++) {
int index = toIndex(additionalCodes[i][0]);
--- a/jdk/test/java/util/Formatter/FailingConstructors.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/Formatter/FailingConstructors.java Mon Mar 07 14:48:27 2011 -0800
@@ -34,6 +34,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.nio.file.Files;
import java.util.Formatter;
public class FailingConstructors {
@@ -47,9 +48,7 @@
/* create the file and write its contents */
File file = File.createTempFile(fileName, null);
file.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(FILE_CONTENTS.getBytes());
- fos.close();
+ Files.write(file.toPath(), FILE_CONTENTS.getBytes());
test(true, file);
file.delete();
--- a/jdk/test/java/util/Locale/LocaleEnhanceTest.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/Locale/LocaleEnhanceTest.java Mon Mar 07 14:48:27 2011 -0800
@@ -1204,14 +1204,12 @@
locale = new Locale(lang, country, variant);
}
- // desrialize
- try {
- FileInputStream fis = new FileInputStream(testfile);
- ObjectInputStream ois = new ObjectInputStream(fis);
-
+ // deserialize
+ try (FileInputStream fis = new FileInputStream(testfile);
+ ObjectInputStream ois = new ObjectInputStream(fis))
+ {
Object o = ois.readObject();
assertEquals("Deserialize Java 6 Locale " + locale, o, locale);
- ois.close();
} catch (Exception e) {
errln("Exception while reading " + testfile.getAbsolutePath() + " - " + e.getMessage());
}
--- a/jdk/test/java/util/ResourceBundle/Bug6204853.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/ResourceBundle/Bug6204853.java Mon Mar 07 14:48:27 2011 -0800
@@ -39,24 +39,19 @@
public final class Bug6204853 {
public Bug6204853() {
- try {
- String srcDir = System.getProperty("test.src", ".");
- FileInputStream fis8859_1 =
- new FileInputStream(new File(srcDir, "Bug6204853.properties"));
- FileInputStream fisUtf8 =
- new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
- InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8");
-
+ String srcDir = System.getProperty("test.src", ".");
+ try (FileInputStream fis8859_1 =
+ new FileInputStream(new File(srcDir, "Bug6204853.properties"));
+ FileInputStream fisUtf8 =
+ new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
+ InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
+ {
PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);
String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
String[] array = createKeyValueArray(bundle);
- isrUtf8.close();
- fisUtf8.close();
- fis8859_1.close();
-
if (!Arrays.equals(arrayUtf8, array)) {
throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
}
--- a/jdk/test/java/util/Scanner/FailingConstructors.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/Scanner/FailingConstructors.java Mon Mar 07 14:48:27 2011 -0800
@@ -33,6 +33,7 @@
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.file.Files;
import java.util.Scanner;
public class FailingConstructors {
@@ -46,9 +47,7 @@
/* create the file and write its contents */
File file = File.createTempFile(fileName, null);
file.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(FILE_CONTENTS.getBytes());
- fos.close();
+ Files.write(file.toPath(), FILE_CONTENTS.getBytes());
test(true, file);
file.delete();
--- a/jdk/test/java/util/jar/JarEntry/GetMethodsReturnClones.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/jar/JarEntry/GetMethodsReturnClones.java Mon Mar 07 14:48:27 2011 -0800
@@ -40,22 +40,21 @@
System.getProperty("file.separator");
public static void main(String[] args) throws Exception {
- JarFile jf = new JarFile(BASE + "test.jar", true);
-
- byte[] buffer = new byte[8192];
- Enumeration<JarEntry> e = jf.entries();
- List<JarEntry> entries = new ArrayList<JarEntry>();
- while (e.hasMoreElements()) {
- JarEntry je = e.nextElement();
- entries.add(je);
- InputStream is = jf.getInputStream(je);
- while (is.read(buffer, 0, buffer.length) != -1) {
- // we just read. this will throw a SecurityException
- // if a signature/digest check fails.
+ List<JarEntry> entries = new ArrayList<>();
+ try (JarFile jf = new JarFile(BASE + "test.jar", true)) {
+ byte[] buffer = new byte[8192];
+ Enumeration<JarEntry> e = jf.entries();
+ while (e.hasMoreElements()) {
+ JarEntry je = e.nextElement();
+ entries.add(je);
+ try (InputStream is = jf.getInputStream(je)) {
+ while (is.read(buffer, 0, buffer.length) != -1) {
+ // we just read. this will throw a SecurityException
+ // if a signature/digest check fails.
+ }
+ }
}
- is.close();
}
- jf.close();
for (JarEntry je : entries) {
Certificate[] certs = je.getCertificates();
--- a/jdk/test/java/util/jar/JarFile/ScanSignedJar.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/jar/JarFile/ScanSignedJar.java Mon Mar 07 14:48:27 2011 -0800
@@ -37,25 +37,25 @@
public class ScanSignedJar {
public static void main(String[] args) throws Exception {
- JarFile file = new JarFile(new File(System.getProperty("test.src","."),
- "bogus-signerinfo-attr.jar"));
- byte[] buffer = new byte[8192];
boolean isSigned = false;
+ try (JarFile file = new JarFile(new File(System.getProperty("test.src","."),
+ "bogus-signerinfo-attr.jar"))) {
+ byte[] buffer = new byte[8192];
- for (Enumeration entries = file.entries(); entries.hasMoreElements();) {
- JarEntry entry = (JarEntry) entries.nextElement();
- InputStream jis = file.getInputStream(entry);
- while (jis.read(buffer, 0, buffer.length) != -1) {
- // read the jar entry
+ for (Enumeration entries = file.entries(); entries.hasMoreElements();) {
+ JarEntry entry = (JarEntry) entries.nextElement();
+ try (InputStream jis = file.getInputStream(entry)) {
+ while (jis.read(buffer, 0, buffer.length) != -1) {
+ // read the jar entry
+ }
+ }
+ if (entry.getCertificates() != null) {
+ isSigned = true;
+ }
+ System.out.println((isSigned ? "[signed] " : "\t ") +
+ entry.getName());
}
- jis.close();
- if (entry.getCertificates() != null) {
- isSigned = true;
- }
- System.out.println((isSigned ? "[signed] " : "\t ") +
- entry.getName());
}
- file.close();
if (isSigned) {
System.out.println("\nJAR file has signed entries");
--- a/jdk/test/java/util/zip/Available.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/Available.java Mon Mar 07 14:48:27 2011 -0800
@@ -44,14 +44,17 @@
File f = new File(System.getProperty("test.src", "."), "input.jar");
// test ZipInputStream
- ZipInputStream z = new ZipInputStream(new FileInputStream(f));
- z.getNextEntry();
- tryAvail(z);
+ try (FileInputStream fis = new FileInputStream(f);
+ ZipInputStream z = new ZipInputStream(fis))
+ {
+ z.getNextEntry();
+ tryAvail(z);
+ }
// test InflaterInputStream
- ZipFile zfile = new ZipFile(f);
- tryAvail(zfile.getInputStream(zfile.getEntry("Available.java")));
- z.close();
+ try (ZipFile zfile = new ZipFile(f)) {
+ tryAvail(zfile.getInputStream(zfile.getEntry("Available.java")));
+ }
}
static void tryAvail(InputStream in) throws Exception {
@@ -67,20 +70,21 @@
// To reproduce 4401122
private static void test2() throws Exception {
File f = new File(System.getProperty("test.src", "."), "input.jar");
- ZipFile zf = new ZipFile(f);
- InputStream in = zf.getInputStream(zf.getEntry("Available.java"));
+ try (ZipFile zf = new ZipFile(f)) {
+ InputStream in = zf.getInputStream(zf.getEntry("Available.java"));
- int initialAvailable = in.available();
- in.read();
- if (in.available() != initialAvailable - 1)
- throw new RuntimeException("Available not decremented.");
- for(int j=0; j<initialAvailable-1; j++)
+ int initialAvailable = in.available();
in.read();
- if (in.available() != 0)
- throw new RuntimeException();
- in.close();
- if (in.available() != 0)
- throw new RuntimeException();
+ if (in.available() != initialAvailable - 1)
+ throw new RuntimeException("Available not decremented.");
+ for(int j=0; j<initialAvailable-1; j++)
+ in.read();
+ if (in.available() != 0)
+ throw new RuntimeException();
+ in.close();
+ if (in.available() != 0)
+ throw new RuntimeException();
+ }
}
}
--- a/jdk/test/java/util/zip/FileBuilder.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/FileBuilder.java Mon Mar 07 14:48:27 2011 -0800
@@ -53,25 +53,24 @@
filetype.equals("SlightlyCompressible")))
usageError();
- RandomAccessFile raf = new RandomAccessFile(filename, "rw");
+ try (RandomAccessFile raf = new RandomAccessFile(filename, "rw")) {
+ if (filetype.equals("SlightlyCompressible")) {
+ byte[] randomBytes = new byte[16384];
+ byte[] nullBytes = new byte[randomBytes.length/10];
+ Random rand = new Random();
+ for (int i = 0; raf.length() < filesize; ++i) {
+ rand.nextBytes(randomBytes);
+ raf.write(nullBytes);
+ raf.write(randomBytes);
+ }
+ }
- if (filetype.equals("SlightlyCompressible")) {
- byte[] randomBytes = new byte[16384];
- byte[] nullBytes = new byte[randomBytes.length/10];
- Random rand = new Random();
- for (int i = 0; raf.length() < filesize; ++i) {
- rand.nextBytes(randomBytes);
- raf.write(nullBytes);
- raf.write(randomBytes);
- }
+ // Make sure file is exactly the requested size, and that
+ // a unique identifying trailer is written.
+ byte[] filenameBytes = filename.getBytes("UTF8");
+ raf.seek(filesize-filenameBytes.length);
+ raf.write(filenameBytes);
+ raf.setLength(filesize);
}
-
- // Make sure file is exactly the requested size, and that
- // a unique identifying trailer is written.
- byte[] filenameBytes = filename.getBytes("UTF8");
- raf.seek(filesize-filenameBytes.length);
- raf.write(filenameBytes);
- raf.setLength(filesize);
- raf.close();
}
}
--- a/jdk/test/java/util/zip/GZIP/Accordion.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/GZIP/Accordion.java Mon Mar 07 14:48:27 2011 -0800
@@ -64,16 +64,13 @@
System.out.println("count="+count);
Thread compressor = new Thread() { public void run() {
- try {
- final GZIPOutputStream s = new GZIPOutputStream(out);
+ try (GZIPOutputStream s = new GZIPOutputStream(out)) {
for (long i = 0; i < count; i++)
s.write(data, 0, data.length);
- s.close();
} catch (Throwable t) { trouble = t; }}};
Thread uncompressor = new Thread() { public void run() {
- try {
- final GZIPInputStream s = new GZIPInputStream(in);
+ try (GZIPInputStream s = new GZIPInputStream(in)) {
final byte[] maybeBytes = new byte[data.length];
for (long i = 0; i < count; i++) {
readFully(s, maybeBytes);
@@ -82,7 +79,6 @@
}
if (s.read(maybeBytes, 0, 1) > 0)
throw new Exception("Unexpected NON-EOF");
- s.close();
} catch (Throwable t) { trouble = t; }}};
compressor.start(); uncompressor.start();
--- a/jdk/test/java/util/zip/GZIP/GZIPInputStreamRead.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/GZIP/GZIPInputStreamRead.java Mon Mar 07 14:48:27 2011 -0800
@@ -44,9 +44,9 @@
rnd.nextBytes(src);
srcBAOS.write(src);
- GZIPOutputStream gzos = new GZIPOutputStream(dstBAOS);
- gzos.write(src);
- gzos.close();
+ try (GZIPOutputStream gzos = new GZIPOutputStream(dstBAOS)) {
+ gzos.write(src);
+ }
}
byte[] srcBytes = srcBAOS.toByteArray();
byte[] dstBytes = dstBAOS.toByteArray();
@@ -75,26 +75,26 @@
int readBufSize, int gzisBufSize)
throws Throwable
{
- GZIPInputStream gzis = new GZIPInputStream(
- new ByteArrayInputStream(dst),
- gzisBufSize);
- byte[] result = new byte[src.length + 10];
- byte[] buf = new byte[readBufSize];
- int n = 0;
- int off = 0;
+ try (ByteArrayInputStream bais = new ByteArrayInputStream(dst);
+ GZIPInputStream gzis = new GZIPInputStream(bais, gzisBufSize))
+ {
+ byte[] result = new byte[src.length + 10];
+ byte[] buf = new byte[readBufSize];
+ int n = 0;
+ int off = 0;
- while ((n = gzis.read(buf, 0, buf.length)) != -1) {
- System.arraycopy(buf, 0, result, off, n);
- off += n;
- // no range check, if overflow, let it fail
+ while ((n = gzis.read(buf, 0, buf.length)) != -1) {
+ System.arraycopy(buf, 0, result, off, n);
+ off += n;
+ // no range check, if overflow, let it fail
+ }
+ if (off != src.length || gzis.available() != 0 ||
+ !Arrays.equals(src, Arrays.copyOf(result, off))) {
+ throw new RuntimeException(
+ "GZIPInputStream reading failed! " +
+ ", src.len=" + src.length +
+ ", read=" + off);
+ }
}
- if (off != src.length || gzis.available() != 0 ||
- !Arrays.equals(src, Arrays.copyOf(result, off))) {
- throw new RuntimeException(
- "GZIPInputStream reading failed! " +
- ", src.len=" + src.length +
- ", read=" + off);
- }
- gzis.close();
}
}
--- a/jdk/test/java/util/zip/InflateIn_DeflateOut.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/InflateIn_DeflateOut.java Mon Mar 07 14:48:27 2011 -0800
@@ -134,14 +134,14 @@
PairedOutputStream pos = new PairedOutputStream(pis);
pis.setPairedOutputStream(pos);
- DeflaterOutputStream dos = new DeflaterOutputStream(pos, true);
byte[] data = new byte[random.nextInt(1024 * 1024)];
byte[] buf = new byte[data.length];
random.nextBytes(data);
- dos.write(data);
- dos.close();
+ try (DeflaterOutputStream dos = new DeflaterOutputStream(pos, true)) {
+ dos.write(data);
+ }
check(readFully(iis, buf, buf.length));
check(Arrays.equals(data, buf));
}
--- a/jdk/test/java/util/zip/InfoZip.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/InfoZip.java Mon Mar 07 14:48:27 2011 -0800
@@ -85,41 +85,37 @@
//----------------------------------------------------------------
File f = new File("InfoZip.zip");
- OutputStream os = new FileOutputStream(f);
- os.write(new byte[]
- {'P', 'K', 3, 4, 10, 0, 0, 0, 0, 0, -68, 8, 'k',
- '2', 'V', -7, 'm', 9, 20, 0, 0, 0, 20, 0, 0, 0,
- 8, 0, 21, 0, 's', 'o', 'm', 'e', 'F', 'i', 'l', 'e', 'U',
- 'T', 9, 0, 3, 't', '_', '1', 'B', 't', '_', '1', 'B', 'U',
- 'x', 4, 0, -14, 'v', 26, 4, 'M', 'e', 's', 's', 'a', 'g',
- 'e', ' ', 'i', 'n', ' ', 'a', ' ', 'B', 'o', 't', 't', 'l', 'e',
- 10, 'P', 'K', 1, 2, 23, 3, 10, 0, 0, 0, 0, 0,
- -68, 8, 'k', '2', 'V', -7, 'm', 9, 20, 0, 0, 0, 20,
- 0, 0, 0, 8, 0, 13, 0, 0, 0, 0, 0, 1, 0,
- 0, 0, -92, -127, 0, 0, 0, 0, 's', 'o', 'm', 'e', 'F',
- 'i', 'l', 'e', 'U', 'T', 5, 0, 3, 't', '_', '1', 'B', 'U',
- 'x', 0, 0, 'P', 'K', 5, 6, 0, 0, 0, 0, 1, 0,
- 1, 0, 'C', 0, 0, 0, 'O', 0, 0, 0, 0, 0, });
- os.close();
+ try (OutputStream os = new FileOutputStream(f)) {
+ os.write(new byte[]
+ {'P', 'K', 3, 4, 10, 0, 0, 0, 0, 0, -68, 8, 'k',
+ '2', 'V', -7, 'm', 9, 20, 0, 0, 0, 20, 0, 0, 0,
+ 8, 0, 21, 0, 's', 'o', 'm', 'e', 'F', 'i', 'l', 'e', 'U',
+ 'T', 9, 0, 3, 't', '_', '1', 'B', 't', '_', '1', 'B', 'U',
+ 'x', 4, 0, -14, 'v', 26, 4, 'M', 'e', 's', 's', 'a', 'g',
+ 'e', ' ', 'i', 'n', ' ', 'a', ' ', 'B', 'o', 't', 't', 'l', 'e',
+ 10, 'P', 'K', 1, 2, 23, 3, 10, 0, 0, 0, 0, 0,
+ -68, 8, 'k', '2', 'V', -7, 'm', 9, 20, 0, 0, 0, 20,
+ 0, 0, 0, 8, 0, 13, 0, 0, 0, 0, 0, 1, 0,
+ 0, 0, -92, -127, 0, 0, 0, 0, 's', 'o', 'm', 'e', 'F',
+ 'i', 'l', 'e', 'U', 'T', 5, 0, 3, 't', '_', '1', 'B', 'U',
+ 'x', 0, 0, 'P', 'K', 5, 6, 0, 0, 0, 0, 1, 0,
+ 1, 0, 'C', 0, 0, 0, 'O', 0, 0, 0, 0, 0, });
+ }
- ZipFile zf = new ZipFile(f);
ZipEntry ze = null;
- try {
+ try (ZipFile zf = new ZipFile(f)) {
Enumeration<? extends ZipEntry> entries = zf.entries();
ze = entries.nextElement();
check(! entries.hasMoreElements());
checkZipEntry(ze, contents(zf, ze));
- } finally {
- zf.close();
}
- ZipInputStream is = new ZipInputStream(new FileInputStream(f));
- try {
+ try (FileInputStream fis = new FileInputStream(f);
+ ZipInputStream is = new ZipInputStream(fis))
+ {
ze = is.getNextEntry();
checkZipEntry(ze, contents(is));
check(is.getNextEntry() == null);
- } finally {
- is.close();
}
f.delete();
System.out.printf("passed = %d, failed = %d%n", passed, failed);
--- a/jdk/test/java/util/zip/LargeZip.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/LargeZip.java Mon Mar 07 14:48:27 2011 -0800
@@ -98,19 +98,21 @@
}
data = baos.toByteArray();
- ZipOutputStream zos = new ZipOutputStream(
- new BufferedOutputStream(new FileOutputStream(largeFile)));
- long length = 0;
- while (length < fileSize) {
- ZipEntry ze = new ZipEntry("entry-" + length);
- lastEntryName = ze.getName();
- zos.putNextEntry(ze);
- zos.write(data, 0, data.length);
- zos.closeEntry();
- length = largeFile.length();
+ try (FileOutputStream fos = new FileOutputStream(largeFile);
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
+ ZipOutputStream zos = new ZipOutputStream(bos))
+ {
+ long length = 0;
+ while (length < fileSize) {
+ ZipEntry ze = new ZipEntry("entry-" + length);
+ lastEntryName = ze.getName();
+ zos.putNextEntry(ze);
+ zos.write(data, 0, data.length);
+ zos.closeEntry();
+ length = largeFile.length();
+ }
+ System.out.println("Last entry written is " + lastEntryName);
}
- System.out.println("Last entry written is " + lastEntryName);
- zos.close();
}
static void readLargeZip1() throws Throwable {
@@ -143,33 +145,35 @@
static void readLargeZip2() throws Throwable {
- ZipInputStream zis = new ZipInputStream(
- new BufferedInputStream(new FileInputStream(largeFile)));
- ZipEntry entry = null;
- String entryName = null;
- int count = 0;
- while ((entry = zis.getNextEntry()) != null) {
- entryName = entry.getName();
- if (entryName.equals(lastEntryName)) {
- break;
+ try (FileInputStream fis = new FileInputStream(largeFile);
+ BufferedInputStream bis = new BufferedInputStream(fis);
+ ZipInputStream zis = new ZipInputStream(bis))
+ {
+ ZipEntry entry = null;
+ String entryName = null;
+ int count = 0;
+ while ((entry = zis.getNextEntry()) != null) {
+ entryName = entry.getName();
+ if (entryName.equals(lastEntryName)) {
+ break;
+ }
+ count++;
}
- count++;
+ System.out.println("Number of entries read: " + count);
+ System.out.println("Last entry read is " + entryName);
+ check(!entry.isDirectory());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ byte buf[] = new byte[4096];
+ int len;
+ while ((len = zis.read(buf)) >= 0) {
+ baos.write(buf, 0, len);
+ }
+ baos.close();
+ check(Arrays.equals(data, baos.toByteArray()));
+ check(zis.getNextEntry() == null);
}
- System.out.println("Number of entries read: " + count);
- System.out.println("Last entry read is " + entryName);
- check(!entry.isDirectory());
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- byte buf[] = new byte[4096];
- int len;
- while ((len = zis.read(buf)) >= 0) {
- baos.write(buf, 0, len);
- }
- baos.close();
- check(Arrays.equals(data, baos.toByteArray()));
- check(zis.getNextEntry() == null);
- zis.close();
}
--- a/jdk/test/java/util/zip/TestEmptyZip.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/TestEmptyZip.java Mon Mar 07 14:48:27 2011 -0800
@@ -78,67 +78,49 @@
pass();
}
}
- ZipInputStream zis = null;
- try {
- zis = new ZipInputStream(new FileInputStream(f));
+ try (FileInputStream fis = new FileInputStream(f);
+ ZipInputStream zis = new ZipInputStream(fis))
+ {
ZipEntry ze = zis.getNextEntry();
check(ze == null);
} catch (IOException ex) {
unexpected(ex);
- } finally {
- if (zis != null) zis.close();
}
}
static void write(File f) throws Exception {
- ZipOutputStream zos = null;
- try {
- zos = new ZipOutputStream(new FileOutputStream(f));
+ try (FileOutputStream fis = new FileOutputStream(f);
+ ZipOutputStream zos = new ZipOutputStream(fis))
+ {
zos.finish();
- zos.close();
pass();
} catch (Exception ex) {
unexpected(ex);
- } finally {
- if (zos != null) {
- zos.close();
- }
}
}
static void readFile(File f) throws Exception {
- ZipFile zf = null;
- try {
- zf = new ZipFile(f);
+ try (ZipFile zf = new ZipFile(f)) {
Enumeration e = zf.entries();
while (e.hasMoreElements()) {
ZipEntry entry = (ZipEntry) e.nextElement();
fail();
}
- zf.close();
pass();
} catch (Exception ex) {
unexpected(ex);
- } finally {
- if (zf != null) {
- zf.close();
- }
}
}
static void readStream(File f) throws Exception {
- ZipInputStream zis = null;
- try {
- zis = new ZipInputStream(new FileInputStream(f));
+ try (FileInputStream fis = new FileInputStream(f);
+ ZipInputStream zis = new ZipInputStream(fis))
+ {
ZipEntry ze = zis.getNextEntry();
check(ze == null);
byte[] buf = new byte[1024];
check(zis.read(buf, 0, 1024) == -1);
- } finally {
- if (zis != null) {
- zis.close();
- }
}
}
--- a/jdk/test/java/util/zip/ZipCoding.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipCoding.java Mon Mar 07 14:48:27 2011 -0800
@@ -57,59 +57,58 @@
String name, String comment, byte[] bb)
throws Exception
{
- ZipInputStream zis = new ZipInputStream(is, cs);
- ZipEntry e = zis.getNextEntry();
- if (e == null || ! name.equals(e.getName()))
- throw new RuntimeException("ZipIS name doesn't match!");
- byte[] bBuf = new byte[bb.length << 1];
- int n = zis.read(bBuf, 0, bBuf.length);
- if (n != bb.length ||
- !Arrays.equals(bb, Arrays.copyOf(bBuf, n))) {
- throw new RuntimeException("ZipIS content doesn't match!");
+ try (ZipInputStream zis = new ZipInputStream(is, cs)) {
+ ZipEntry e = zis.getNextEntry();
+ if (e == null || ! name.equals(e.getName()))
+ throw new RuntimeException("ZipIS name doesn't match!");
+ byte[] bBuf = new byte[bb.length << 1];
+ int n = zis.read(bBuf, 0, bBuf.length);
+ if (n != bb.length ||
+ !Arrays.equals(bb, Arrays.copyOf(bBuf, n))) {
+ throw new RuntimeException("ZipIS content doesn't match!");
+ }
}
- zis.close();
}
static void testZipFile(File f, Charset cs,
String name, String comment, byte[] bb)
throws Exception
{
- ZipFile zf = new ZipFile(f, cs);
- Enumeration<? extends ZipEntry> zes = zf.entries();
- ZipEntry e = (ZipEntry)zes.nextElement();
- if (! name.equals(e.getName()) ||
- ! comment.equals(e.getComment()))
- throw new RuntimeException("ZipFile: name/comment doesn't match!");
- InputStream is = zf.getInputStream(e);
- if (is == null)
- throw new RuntimeException("ZipFile: getIS failed!");
- byte[] bBuf = new byte[bb.length << 1];
- int n = 0;
- int nn =0;
- while ((nn = is.read(bBuf, n, bBuf.length-n)) != -1) {
- n += nn;
+ try (ZipFile zf = new ZipFile(f, cs)) {
+ Enumeration<? extends ZipEntry> zes = zf.entries();
+ ZipEntry e = (ZipEntry)zes.nextElement();
+ if (! name.equals(e.getName()) ||
+ ! comment.equals(e.getComment()))
+ throw new RuntimeException("ZipFile: name/comment doesn't match!");
+ InputStream is = zf.getInputStream(e);
+ if (is == null)
+ throw new RuntimeException("ZipFile: getIS failed!");
+ byte[] bBuf = new byte[bb.length << 1];
+ int n = 0;
+ int nn =0;
+ while ((nn = is.read(bBuf, n, bBuf.length-n)) != -1) {
+ n += nn;
+ }
+ if (n != bb.length ||
+ !Arrays.equals(bb, Arrays.copyOf(bBuf, n))) {
+ throw new RuntimeException("ZipFile content doesn't match!");
+ }
}
- if (n != bb.length ||
- !Arrays.equals(bb, Arrays.copyOf(bBuf, n))) {
- throw new RuntimeException("ZipFile content doesn't match!");
- }
- zf.close();
}
static void test(String csn, String name, String comment)
throws Exception
{
- byte[] bb = "This is the conent of the zipfile".getBytes("ISO-8859-1");
+ byte[] bb = "This is the content of the zipfile".getBytes("ISO-8859-1");
Charset cs = Charset.forName(csn);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ZipOutputStream zos = new ZipOutputStream(baos, cs);
-
- ZipEntry e = new ZipEntry(name);
- e.setComment(comment);
- zos.putNextEntry(e);
- zos.write(bb, 0, bb.length);
- zos.closeEntry();
- zos.close();
+ try (ZipOutputStream zos = new ZipOutputStream(baos, cs)) {
+ ZipEntry e = new ZipEntry(name);
+ e.setComment(comment);
+ zos.putNextEntry(e);
+ zos.write(bb, 0, bb.length);
+ zos.closeEntry();
+ }
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
testZipInputStream(bis, cs, name, comment, bb);
@@ -121,9 +120,9 @@
File f = new File(new File(System.getProperty("test.dir", ".")),
"zfcoding.zip");
- FileOutputStream fos = new FileOutputStream(f);
- baos.writeTo(fos);
- fos.close();
+ try (FileOutputStream fos = new FileOutputStream(f)) {
+ baos.writeTo(fos);
+ }
testZipFile(f, cs, name, comment, bb);
if ("utf-8".equals(csn)) {
testZipFile(f, Charset.forName("MS932"), name, comment, bb);
--- a/jdk/test/java/util/zip/ZipFile/Assortment.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/Assortment.java Mon Mar 07 14:48:27 2011 -0800
@@ -201,13 +201,12 @@
//----------------------------------------------------------------
// Write zip file using ZipOutputStream
//----------------------------------------------------------------
- ZipOutputStream zos = new ZipOutputStream(
- new FileOutputStream(zipName));
-
- for (Entry e : entries)
- e.write(zos);
-
- zos.close();
+ try (FileOutputStream fos = new FileOutputStream(zipName);
+ ZipOutputStream zos = new ZipOutputStream(fos))
+ {
+ for (Entry e : entries)
+ e.write(zos);
+ }
//----------------------------------------------------------------
// Verify zip file contents using JarFile class
--- a/jdk/test/java/util/zip/ZipFile/Comment.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/Comment.java Mon Mar 07 14:48:27 2011 -0800
@@ -57,16 +57,15 @@
private static void writeZipFile(String name, String comment)
throws IOException
{
- ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(name));
- try {
+ try (FileOutputStream fos = new FileOutputStream(name);
+ ZipOutputStream zos = new ZipOutputStream(fos))
+ {
zos.setComment(comment);
ZipEntry ze = new ZipEntry(entryName);
ze.setMethod(ZipEntry.DEFLATED);
zos.putNextEntry(ze);
new DataOutputStream(zos).writeUTF(entryContents);
zos.closeEntry();
- } finally {
- zos.close();
}
}
@@ -74,30 +73,30 @@
throws Exception
{
// Check that Zip entry was correctly written.
- ZipFile zipFile = new ZipFile(name);
- ZipEntry zipEntry = zipFile.getEntry(entryName);
- InputStream is = zipFile.getInputStream(zipEntry);
- String result = new DataInputStream(is).readUTF();
- if (!result.equals(entryContents))
- throw new Exception("Entry contents corrupted");
+ try (ZipFile zipFile = new ZipFile(name)) {
+ ZipEntry zipEntry = zipFile.getEntry(entryName);
+ InputStream is = zipFile.getInputStream(zipEntry);
+ String result = new DataInputStream(is).readUTF();
+ if (!result.equals(entryContents))
+ throw new Exception("Entry contents corrupted");
+ }
- // Check that comment length was correctly written.
- RandomAccessFile file = new RandomAccessFile(name, "r");
- file.seek(file.length() - comment.length()
- - ZipFile.ENDHDR + ZipFile.ENDCOM);
- int b1 = file.readUnsignedByte();
- int b2 = file.readUnsignedByte();
- if (b1 + (b2 << 8) != comment.length())
- throw new Exception("Zip file comment length corrupted");
+ try (RandomAccessFile file = new RandomAccessFile(name, "r")) {
+ // Check that comment length was correctly written.
+ file.seek(file.length() - comment.length()
+ - ZipFile.ENDHDR + ZipFile.ENDCOM);
+ int b1 = file.readUnsignedByte();
+ int b2 = file.readUnsignedByte();
+ if (b1 + (b2 << 8) != comment.length())
+ throw new Exception("Zip file comment length corrupted");
- // Check that comment was correctly written.
- file.seek(file.length() - comment.length());
- byte [] bytes = new byte [comment.length()];
- file.readFully(bytes);
- zipFile.close();
- file.close();
- if (! comment.equals(new String(bytes, "UTF8")))
- throw new Exception("Zip file comment corrupted");
+ // Check that comment was correctly written.
+ file.seek(file.length() - comment.length());
+ byte [] bytes = new byte [comment.length()];
+ file.readFully(bytes);
+ if (! comment.equals(new String(bytes, "UTF8")))
+ throw new Exception("Zip file comment corrupted");
+ }
}
private static String buildComment(int length) {
--- a/jdk/test/java/util/zip/ZipFile/CopyJar.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/CopyJar.java Mon Mar 07 14:48:27 2011 -0800
@@ -31,18 +31,18 @@
public class CopyJar {
public static void main(String args[]) throws Exception {
- ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
- "input.jar"));
- ZipEntry ze = zf.getEntry("ReleaseInflater.java");
- ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
- InputStream in = zf.getInputStream(ze);
- byte[] b = new byte[128];
- int n;
- zos.putNextEntry(ze);
- while((n = in.read(b)) != -1) {
- zos.write(b, 0, n);
+ try (ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
+ "input.jar"))) {
+ ZipEntry ze = zf.getEntry("ReleaseInflater.java");
+ ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
+ InputStream in = zf.getInputStream(ze);
+ byte[] b = new byte[128];
+ int n;
+ zos.putNextEntry(ze);
+ while((n = in.read(b)) != -1) {
+ zos.write(b, 0, n);
+ }
+ zos.close();
}
- zos.close();
- zf.close();
}
}
--- a/jdk/test/java/util/zip/ZipFile/CorruptedZipFiles.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/CorruptedZipFiles.java Mon Mar 07 14:48:27 2011 -0800
@@ -47,21 +47,19 @@
}
public static void main(String[] args) throws Exception {
- ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("x.zip"));
- try {
+ try (FileOutputStream fos = new FileOutputStream("x.zip");
+ ZipOutputStream zos = new ZipOutputStream(fos))
+ {
ZipEntry e = new ZipEntry("x");
zos.putNextEntry(e);
zos.write((int)'x');
- } finally {
- zos.close();
}
int len = (int)(new File("x.zip").length());
byte[] good = new byte[len];
- FileInputStream fis = new FileInputStream("x.zip");
- fis.read(good);
- fis.close();
- fis = null;
+ try (FileInputStream fis = new FileInputStream("x.zip")) {
+ fis.read(good);
+ }
new File("x.zip").delete();
int endpos = len - ENDHDR;
@@ -150,17 +148,14 @@
boolean getInputStream) {
String zipName = "bad" + (uniquifier++) + ".zip";
try {
- FileOutputStream fos = new FileOutputStream(zipName);
- fos.write(data);
- fos.close();
- ZipFile zf = new ZipFile(zipName);
- try {
+ try (FileOutputStream fos = new FileOutputStream(zipName)) {
+ fos.write(data);
+ }
+ try (ZipFile zf = new ZipFile(zipName)) {
if (getInputStream) {
InputStream is = zf.getInputStream(new ZipEntry("x"));
is.read();
}
- } finally {
- zf.close();
}
fail("Failed to throw expected ZipException");
} catch (ZipException e) {
@@ -170,8 +165,7 @@
unexpected(e);
} catch (Throwable t) {
unexpected(t);
- }
- finally {
+ } finally {
new File(zipName).delete();
}
}
--- a/jdk/test/java/util/zip/ZipFile/DeleteTempJar.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/DeleteTempJar.java Mon Mar 07 14:48:27 2011 -0800
@@ -53,34 +53,34 @@
{
final File zf = File.createTempFile("deletetemp", ".jar");
zf.deleteOnExit();
- JarOutputStream jos = new JarOutputStream(
- new FileOutputStream(zf));
- JarEntry je = new JarEntry("entry");
- jos.putNextEntry(je);
- jos.write("hello, world".getBytes("ASCII"));
- jos.close();
+ try (FileOutputStream fos = new FileOutputStream(zf);
+ JarOutputStream jos = new JarOutputStream(fos))
+ {
+ JarEntry je = new JarEntry("entry");
+ jos.putNextEntry(je);
+ jos.write("hello, world".getBytes("ASCII"));
+ }
HttpServer server = HttpServer.create(
new InetSocketAddress((InetAddress) null, 0), 0);
HttpContext context = server.createContext("/",
new HttpHandler() {
public void handle(HttpExchange e) {
- try {
- FileInputStream fis = new FileInputStream(zf);
- e.sendResponseHeaders(200, zf.length());
- OutputStream os = e.getResponseBody();
- byte[] buf = new byte[1024];
- int count = 0;
- while ((count = fis.read(buf)) != -1) {
- os.write(buf, 0, count);
+ try (FileInputStream fis = new FileInputStream(zf)) {
+ e.sendResponseHeaders(200, zf.length());
+ OutputStream os = e.getResponseBody();
+ byte[] buf = new byte[1024];
+ int count = 0;
+ while ((count = fis.read(buf)) != -1) {
+ os.write(buf, 0, count);
+ }
+ } catch (Exception ex) {
+ unexpected(ex);
+ } finally {
+ e.close();
}
- fis.close();
- e.close();
- } catch (Exception ex) {
- unexpected(ex);
}
- }
- });
+ });
server.start();
URL url = new URL("jar:http://localhost:"
--- a/jdk/test/java/util/zip/ZipFile/EnumAfterClose.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/EnumAfterClose.java Mon Mar 07 14:48:27 2011 -0800
@@ -33,10 +33,12 @@
public class EnumAfterClose {
public static void main(String args[]) throws Exception {
- ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
- "input.zip"));
- Enumeration e = zf.entries();
- zf.close();
+ Enumeration e;
+ try (ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
+ "input.zip"))) {
+ e = zf.entries();
+ }
+ // ensure that the ZipFile is closed before checking the Enumeration
try {
if (e.hasMoreElements()) {
ZipEntry ze = (ZipEntry)e.nextElement();
--- a/jdk/test/java/util/zip/ZipFile/GetDirEntry.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/GetDirEntry.java Mon Mar 07 14:48:27 2011 -0800
@@ -32,12 +32,12 @@
public class GetDirEntry {
public static void main(String args[]) throws Exception {
- ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
- "input.jar"));
- ZipEntry ze = zf.getEntry("META-INF");
- if (ze == null) {
- throw new Exception("failed to find a directory entry");
+ try (ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
+ "input.jar"))) {
+ ZipEntry ze = zf.getEntry("META-INF");
+ if (ze == null) {
+ throw new Exception("failed to find a directory entry");
+ }
}
- zf.close();
}
}
--- a/jdk/test/java/util/zip/ZipFile/LargeZipFile.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/LargeZipFile.java Mon Mar 07 14:48:27 2011 -0800
@@ -93,51 +93,50 @@
baos.write(bb.array(), 0, DATA_SIZE);
}
data = baos.toByteArray();
-
- ZipOutputStream zos = new ZipOutputStream(
- new BufferedOutputStream(new FileOutputStream(largeFile)));
- long length = 0;
- while (length < fileSize) {
- ZipEntry ze = new ZipEntry("entry-" + length);
- lastEntryName = ze.getName();
- zos.putNextEntry(ze);
- zos.write(data, 0, data.length);
- zos.closeEntry();
- length = largeFile.length();
+ try (FileOutputStream fos = new FileOutputStream(largeFile);
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
+ ZipOutputStream zos = new ZipOutputStream(bos))
+ {
+ long length = 0;
+ while (length < fileSize) {
+ ZipEntry ze = new ZipEntry("entry-" + length);
+ lastEntryName = ze.getName();
+ zos.putNextEntry(ze);
+ zos.write(data, 0, data.length);
+ zos.closeEntry();
+ length = largeFile.length();
+ }
+ System.out.println("Last entry written is " + lastEntryName);
}
- System.out.println("Last entry written is " + lastEntryName);
- zos.close();
}
static void readLargeZip() throws Throwable {
- ZipFile zipFile = new ZipFile(largeFile);
- ZipEntry entry = null;
- String entryName = null;
- int count = 0;
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
- entryName = entry.getName();
- count++;
+ try (ZipFile zipFile = new ZipFile(largeFile)) {
+ ZipEntry entry = null;
+ String entryName = null;
+ int count = 0;
+ Enumeration<? extends ZipEntry> entries = zipFile.entries();
+ while (entries.hasMoreElements()) {
+ entry = entries.nextElement();
+ entryName = entry.getName();
+ count++;
+ }
+ System.out.println("Number of entries read: " + count);
+ System.out.println("Last entry read is " + entryName);
+ check(!entry.isDirectory());
+ if (check(entryName.equals(lastEntryName))) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ InputStream is = zipFile.getInputStream(entry);
+ byte buf[] = new byte[4096];
+ int len;
+ while ((len = is.read(buf)) >= 0) {
+ baos.write(buf, 0, len);
+ }
+ baos.close();
+ is.close();
+ check(Arrays.equals(data, baos.toByteArray()));
+ }
}
- System.out.println("Number of entries read: " + count);
- System.out.println("Last entry read is " + entryName);
- check(!entry.isDirectory());
- if (check(entryName.equals(lastEntryName))) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- InputStream is = zipFile.getInputStream(entry);
- byte buf[] = new byte[4096];
- int len;
- while ((len = is.read(buf)) >= 0) {
- baos.write(buf, 0, len);
- }
- baos.close();
- is.close();
- check(Arrays.equals(data, baos.toByteArray()));
- }
- try {
- zipFile.close();
- } catch (IOException ioe) {/* what can you do */ }
}
//--------------------- Infrastructure ---------------------------
--- a/jdk/test/java/util/zip/ZipFile/ManyEntries.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/ManyEntries.java Mon Mar 07 14:48:27 2011 -0800
@@ -55,10 +55,10 @@
File zipFile = new File(++uniquifier + ".zip");
try {
zipFile.delete();
- ZipOutputStream zos = new ZipOutputStream(
- new BufferedOutputStream(
- new FileOutputStream(zipFile)));
- try {
+ try (FileOutputStream fos = new FileOutputStream(zipFile);
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
+ ZipOutputStream zos = new ZipOutputStream(bos))
+ {
for (int i = 0; i < N; i++) {
ZipEntry e = new ZipEntry("DIR/"+i);
e.setMethod(method);
@@ -75,13 +75,9 @@
zos.putNextEntry(e);
zos.write(i);
}
- } finally {
- zos.close();
- zos = null;
}
- ZipFile zip = zip = new ZipFile(zipFile);
- try {
+ try (ZipFile zip = new ZipFile(zipFile)) {
if (! (zip.size() == N))
throw new Exception("Bad ZipFile size: " + zip.size());
Enumeration entries = zip.entries();
@@ -104,11 +100,8 @@
}
if (entries.hasMoreElements())
throw new Exception("too many elements");
- } finally {
- zip.close();
}
- }
- finally {
+ } finally {
zipFile.delete();
}
}
--- a/jdk/test/java/util/zip/ZipFile/ManyZipFiles.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/ManyZipFiles.java Mon Mar 07 14:48:27 2011 -0800
@@ -51,14 +51,14 @@
// Create some zip data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ZipOutputStream zos = new ZipOutputStream(baos);
- ZipEntry ze = new ZipEntry("test");
- zos.putNextEntry(ze);
- byte[] hello = "hello, world".getBytes("ASCII");
- zos.write(hello, 0, hello.length);
- zos.closeEntry();
- zos.finish();
- zos.close();
+ try (ZipOutputStream zos = new ZipOutputStream(baos)) {
+ ZipEntry ze = new ZipEntry("test");
+ zos.putNextEntry(ze);
+ byte[] hello = "hello, world".getBytes("ASCII");
+ zos.write(hello, 0, hello.length);
+ zos.closeEntry();
+ zos.finish();
+ }
byte[] data = baos.toByteArray();
ZipFile zips[] = new ZipFile[numFiles];
@@ -90,9 +90,9 @@
for (int i = 0; i < numFiles; i++) {
File f = File.createTempFile("test", ".zip", tmpdir);
f.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(data, 0, data.length);
- fos.close();
+ try (FileOutputStream fos = new FileOutputStream(f)) {
+ fos.write(data, 0, data.length);
+ }
try {
zips[i] = new ZipFile(f);
} catch (Throwable t) {
@@ -102,11 +102,12 @@
}
}
} finally {
- // This finally block is due to bug 4171239. On windows, if the
+ // This finally block is due to bug 4171239. On Windows, if the
// file is still open at the end of the VM, deleteOnExit won't
// take place. "new ZipFile(...)" opens the zip file, so we have
- // to explicity close those opened above. This finally block can
- // be removed when 4171239 is fixed.
+ // to explicitly close those opened above. This finally block can
+ // be removed when 4171239 is fixed. See also 6357433, against which
+ // 4171239 was closed as a duplicate.
for (int i = 0; i < numFiles; i++) {
if (zips[i] != null) {
try {
--- a/jdk/test/java/util/zip/ZipFile/ReadAfterClose.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/ReadAfterClose.java Mon Mar 07 14:48:27 2011 -0800
@@ -34,10 +34,13 @@
public class ReadAfterClose {
public static void main(String[] argv) throws Exception {
- ZipFile zf = new ZipFile(new File(System.getProperty("test.src","."),"crash.jar"));
- ZipEntry zent = zf.getEntry("Test.java");
- InputStream in = zf.getInputStream(zent);
- zf.close();
+ InputStream in;
+ try (ZipFile zf = new ZipFile(
+ new File(System.getProperty("test.src","."),"crash.jar"))) {
+ ZipEntry zent = zf.getEntry("Test.java");
+ in = zf.getInputStream(zent);
+ }
+ // ensure zf is closed at this point
try {
in.read();
} catch (IOException e) {
--- a/jdk/test/java/util/zip/ZipFile/ReadZip.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/ReadZip.java Mon Mar 07 14:48:27 2011 -0800
@@ -27,6 +27,10 @@
*/
import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.StandardOpenOption;
import java.util.zip.*;
public class ReadZip {
@@ -38,71 +42,62 @@
}
public static void main(String args[]) throws Exception {
- ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
- "input.zip"));
-
- // Make sure we throw NPE on null objects
- try { unreached (zf.getEntry(null)); }
- catch (NullPointerException e) {}
+ try (ZipFile zf = new ZipFile(new File(System.getProperty("test.src", "."),
+ "input.zip"))) {
+ // Make sure we throw NPE on null objects
+ try { unreached (zf.getEntry(null)); }
+ catch (NullPointerException e) {}
- try { unreached (zf.getInputStream(null)); }
- catch (NullPointerException e) {}
+ try { unreached (zf.getInputStream(null)); }
+ catch (NullPointerException e) {}
- ZipEntry ze = zf.getEntry("ReadZip.java");
- if (ze == null) {
- throw new Exception("cannot read from zip file");
+ ZipEntry ze = zf.getEntry("ReadZip.java");
+ if (ze == null) {
+ throw new Exception("cannot read from zip file");
+ }
}
- zf.close();
// Make sure we can read the zip file that has some garbage
// bytes padded at the end.
- FileInputStream fis = new FileInputStream(
- new File(System.getProperty("test.src", "."),
- "input.zip"));
- File newZip = new File(System.getProperty("test.dir", "."),
- "input2.zip");
- FileOutputStream fos = new FileOutputStream(newZip);
+ File newZip = new File(System.getProperty("test.dir", "."), "input2.zip");
+ Files.copy(Paths.get(System.getProperty("test.src", ""), "input.zip"),
+ newZip.toPath(), StandardCopyOption.REPLACE_EXISTING);
- byte[] buf = new byte[1024];
- int n = 0;
- while ((n = fis.read(buf)) != -1) {
- fos.write(buf, 0, n);
+ // pad some bytes
+ try (OutputStream os = Files.newOutputStream(newZip.toPath(),
+ StandardOpenOption.APPEND)) {
+ os.write(1); os.write(3); os.write(5); os.write(7);
}
- fis.close();
- // pad some bytes
- fos.write(1); fos.write(3); fos.write(5); fos.write(7);
- fos.close();
- try {
- zf = new ZipFile(newZip);
- ze = zf.getEntry("ReadZip.java");
+
+ try (ZipFile zf = new ZipFile(newZip)) {
+ ZipEntry ze = zf.getEntry("ReadZip.java");
if (ze == null) {
throw new Exception("cannot read from zip file");
}
} finally {
- zf.close();
newZip.delete();
}
// Read zip file comment
try {
+ try (FileOutputStream fos = new FileOutputStream(newZip);
+ ZipOutputStream zos = new ZipOutputStream(fos))
+ {
+ ZipEntry ze = new ZipEntry("ZipEntry");
+ zos.putNextEntry(ze);
+ zos.write(1); zos.write(2); zos.write(3); zos.write(4);
+ zos.closeEntry();
+ zos.setComment("This is the comment for testing");
+ }
- ZipOutputStream zos = new ZipOutputStream(
- new FileOutputStream(newZip));
- ze = new ZipEntry("ZipEntry");
- zos.putNextEntry(ze);
- zos.write(1); zos.write(2); zos.write(3); zos.write(4);
- zos.closeEntry();
- zos.setComment("This is the comment for testing");
- zos.close();
-
- zf = new ZipFile(newZip);
- ze = zf.getEntry("ZipEntry");
- if (ze == null)
- throw new Exception("cannot read entry from zip file");
- if (!"This is the comment for testing".equals(zf.getComment()))
- throw new Exception("cannot read comment from zip file");
+ try (ZipFile zf = new ZipFile(newZip)) {
+ ZipEntry ze = zf.getEntry("ZipEntry");
+ if (ze == null)
+ throw new Exception("cannot read entry from zip file");
+ if (!"This is the comment for testing".equals(zf.getComment()))
+ throw new Exception("cannot read comment from zip file");
+ }
} finally {
- zf.close();
newZip.delete();
}
--- a/jdk/test/java/util/zip/ZipFile/ShortRead.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/ZipFile/ShortRead.java Mon Mar 07 14:48:27 2011 -0800
@@ -38,27 +38,29 @@
try {
final String entryName = "abc";
final String data = "Data disponible";
- final ZipOutputStream zos =
- new ZipOutputStream(new FileOutputStream(zFile));
- zos.putNextEntry(new ZipEntry(entryName));
- zos.write(data.getBytes("ASCII"));
- zos.closeEntry();
- zos.close();
+ try (FileOutputStream fos = new FileOutputStream(zFile);
+ ZipOutputStream zos = new ZipOutputStream(fos))
+ {
+ zos.putNextEntry(new ZipEntry(entryName));
+ zos.write(data.getBytes("ASCII"));
+ zos.closeEntry();
+ }
- final ZipFile zipFile = new ZipFile(zFile);
- final ZipEntry zentry = zipFile.getEntry(entryName);
- final InputStream inputStream = zipFile.getInputStream(zentry);
- System.out.printf("size=%d csize=%d available=%d%n",
- zentry.getSize(),
- zentry.getCompressedSize(),
- inputStream.available());
- byte[] buf = new byte[data.length()];
- final int count = inputStream.read(buf);
- if (! new String(buf, "ASCII").equals(data) ||
- count != data.length())
- throw new Exception("short read?");
- zipFile.close();
+ try (ZipFile zipFile = new ZipFile(zFile)) {
+ final ZipEntry zentry = zipFile.getEntry(entryName);
+ final InputStream inputStream = zipFile.getInputStream(zentry);
+ System.out.printf("size=%d csize=%d available=%d%n",
+ zentry.getSize(),
+ zentry.getCompressedSize(),
+ inputStream.available());
+ byte[] buf = new byte[data.length()];
+ final int count = inputStream.read(buf);
+ if (! new String(buf, "ASCII").equals(data) ||
+ count != data.length())
+ throw new Exception("short read?");
+ }
+ } finally {
+ zFile.delete();
}
- finally { zFile.delete(); }
}
}
--- a/jdk/test/java/util/zip/zip.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/java/util/zip/zip.java Mon Mar 07 14:48:27 2011 -0800
@@ -322,57 +322,57 @@
void create(OutputStream out) throws IOException
{
- ZipOutputStream zos = new ZipOutputStream(out, cs);
- if (flag0) {
- zos.setMethod(ZipOutputStream.STORED);
+ try (ZipOutputStream zos = new ZipOutputStream(out, cs)) {
+ if (flag0) {
+ zos.setMethod(ZipOutputStream.STORED);
+ }
+ for (File file: entries) {
+ addFile(zos, file);
+ }
}
- for (File file: entries) {
- addFile(zos, file);
- }
- zos.close();
}
boolean update(InputStream in, OutputStream out) throws IOException
{
- ZipInputStream zis = new ZipInputStream(in, cs);
- ZipOutputStream zos = new ZipOutputStream(out, cs);
- ZipEntry e = null;
- byte[] buf = new byte[1024];
- int n = 0;
- boolean updateOk = true;
+ try (ZipInputStream zis = new ZipInputStream(in, cs);
+ ZipOutputStream zos = new ZipOutputStream(out, cs))
+ {
+ ZipEntry e = null;
+ byte[] buf = new byte[1024];
+ int n = 0;
+ boolean updateOk = true;
- // put the old entries first, replace if necessary
- while ((e = zis.getNextEntry()) != null) {
- String name = e.getName();
- if (!entryMap.containsKey(name)) { // copy the old stuff
- // do our own compression
- ZipEntry e2 = new ZipEntry(name);
- e2.setMethod(e.getMethod());
- e2.setTime(e.getTime());
- e2.setComment(e.getComment());
- e2.setExtra(e.getExtra());
- if (e.getMethod() == ZipEntry.STORED) {
- e2.setSize(e.getSize());
- e2.setCrc(e.getCrc());
+ // put the old entries first, replace if necessary
+ while ((e = zis.getNextEntry()) != null) {
+ String name = e.getName();
+ if (!entryMap.containsKey(name)) { // copy the old stuff
+ // do our own compression
+ ZipEntry e2 = new ZipEntry(name);
+ e2.setMethod(e.getMethod());
+ e2.setTime(e.getTime());
+ e2.setComment(e.getComment());
+ e2.setExtra(e.getExtra());
+ if (e.getMethod() == ZipEntry.STORED) {
+ e2.setSize(e.getSize());
+ e2.setCrc(e.getCrc());
+ }
+ zos.putNextEntry(e2);
+ while ((n = zis.read(buf, 0, buf.length)) != -1) {
+ zos.write(buf, 0, n);
+ }
+ } else { // replace with the new files
+ File f = entryMap.get(name);
+ addFile(zos, f);
+ entryMap.remove(name);
+ entries.remove(f);
}
- zos.putNextEntry(e2);
- while ((n = zis.read(buf, 0, buf.length)) != -1) {
- zos.write(buf, 0, n);
- }
- } else { // replace with the new files
- File f = entryMap.get(name);
+ }
+
+ // add the remaining new files
+ for (File f: entries) {
addFile(zos, f);
- entryMap.remove(name);
- entries.remove(f);
}
}
-
- // add the remaining new files
- for (File f: entries) {
- addFile(zos, f);
- }
- zis.close();
- zos.close();
return updateOk;
}
@@ -517,25 +517,25 @@
}
void extract(String fname, String files[]) throws IOException {
- ZipFile zf = new ZipFile(fname, cs);
- Set<ZipEntry> dirs = newDirSet();
- Enumeration<? extends ZipEntry> zes = zf.entries();
- while (zes.hasMoreElements()) {
- ZipEntry e = zes.nextElement();
- InputStream is;
- if (files == null) {
- dirs.add(extractFile(zf.getInputStream(e), e));
- } else {
- String name = e.getName();
- for (String file : files) {
- if (name.startsWith(file)) {
- dirs.add(extractFile(zf.getInputStream(e), e));
- break;
+ try (ZipFile zf = new ZipFile(fname, cs)) {
+ Set<ZipEntry> dirs = newDirSet();
+ Enumeration<? extends ZipEntry> zes = zf.entries();
+ while (zes.hasMoreElements()) {
+ ZipEntry e = zes.nextElement();
+ InputStream is;
+ if (files == null) {
+ dirs.add(extractFile(zf.getInputStream(e), e));
+ } else {
+ String name = e.getName();
+ for (String file : files) {
+ if (name.startsWith(file)) {
+ dirs.add(extractFile(zf.getInputStream(e), e));
+ break;
+ }
}
}
}
}
- zf.close();
updateLastModifiedTime(dirs);
}
@@ -607,12 +607,12 @@
}
void list(String fname, String files[]) throws IOException {
- ZipFile zf = new ZipFile(fname, cs);
- Enumeration<? extends ZipEntry> zes = zf.entries();
- while (zes.hasMoreElements()) {
- printEntry(zes.nextElement(), files);
+ try (ZipFile zf = new ZipFile(fname, cs)) {
+ Enumeration<? extends ZipEntry> zes = zf.entries();
+ while (zes.hasMoreElements()) {
+ printEntry(zes.nextElement(), files);
+ }
}
- zf.close();
}
void printEntry(ZipEntry e, String[] files) throws IOException {
--- a/jdk/test/sun/misc/BootClassLoaderHook/TestHook.java Mon Mar 07 14:46:16 2011 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2009, 2010, 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.util.TreeSet;
-import java.util.Set;
-import java.net.URLStreamHandlerFactory;
-import sun.misc.BootClassLoaderHook;
-import sun.misc.URLClassPath;
-
-
-/* @test
- * @bug 6888802
- * @summary Sanity test of BootClassLoaderHook interface
- *
- * @build TestHook
- * @run main TestHook
- */
-
-public class TestHook extends BootClassLoaderHook {
-
- private static final TestHook hook = new TestHook();
- private static Set<String> names = new TreeSet<String>();
- private static final String LOGRECORD_CLASS =
- "java.util.logging.LogRecord";
- private static final String NONEXIST_RESOURCE =
- "non.exist.resource";
- private static final String LIBHELLO = "hello";
-
- public static void main(String[] args) throws Exception {
- BootClassLoaderHook.setHook(hook);
- if (BootClassLoaderHook.getHook() == null) {
- throw new RuntimeException("Null boot classloader hook ");
- }
-
- testHook();
-
- if (!names.contains(LOGRECORD_CLASS)) {
- throw new RuntimeException("loadBootstrapClass for " + LOGRECORD_CLASS + " not called");
- }
-
- if (!names.contains(NONEXIST_RESOURCE)) {
- throw new RuntimeException("getBootstrapResource for " + NONEXIST_RESOURCE + " not called");
- }
- if (!names.contains(LIBHELLO)) {
- throw new RuntimeException("loadLibrary for " + LIBHELLO + " not called");
- }
-
- Set<String> copy = new TreeSet<String>();
- copy.addAll(names);
- for (String s : copy) {
- System.out.println(" Loaded " + s);
- }
- }
-
- private static void testHook() throws Exception {
- Class.forName(LOGRECORD_CLASS);
- ClassLoader.getSystemResource(NONEXIST_RESOURCE);
- try {
- System.loadLibrary(LIBHELLO);
- } catch (UnsatisfiedLinkError e) {
- }
- }
-
- public String loadBootstrapClass(String className) {
- names.add(className);
- return null;
- }
-
- public String getBootstrapResource(String resourceName) {
- names.add(resourceName);
- return null;
- }
-
- public boolean loadLibrary(String libname) {
- names.add(libname);
- return false;
- }
-
- public URLClassPath getBootstrapClassPath(URLClassPath bcp,
- URLStreamHandlerFactory factory) {
- return bcp;
- }
-
- public boolean isCurrentThreadPrefetching() {
- return false;
- }
-
- public boolean prefetchFile(String name) {
- return false;
- }
-}
--- a/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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,7 +23,7 @@
/**
* @test
- * @bug 4898468
+ * @bug 4898468 6994008
* @summary basic test for RSA cipher
* @author Andreas Sterbenz
* @library ..
@@ -38,9 +38,12 @@
public class TestRSACipher extends PKCS11Test {
+ private static final String[] RSA_ALGOS =
+ { "RSA/ECB/PKCS1Padding", "RSA" };
+
public void main(Provider p) throws Exception {
try {
- Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
+ Cipher.getInstance(RSA_ALGOS[0], p);
} catch (GeneralSecurityException e) {
System.out.println("Not supported by provider, skipping");
return;
@@ -55,57 +58,58 @@
b = new byte[16];
random.nextBytes(b);
- Cipher c1 = Cipher.getInstance("RSA/ECB/PKCS1Padding", p);
- Cipher c2 = Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunJCE");
+ for (String rsaAlgo: RSA_ALGOS) {
+ Cipher c1 = Cipher.getInstance(rsaAlgo, p);
+ Cipher c2 = Cipher.getInstance(rsaAlgo, "SunJCE");
- c1.init(Cipher.ENCRYPT_MODE, publicKey);
- e = c1.doFinal(b);
- c1.init(Cipher.DECRYPT_MODE, privateKey);
- d = c1.doFinal(e);
- match(b, d);
- c2.init(Cipher.DECRYPT_MODE, privateKey);
- d = c2.doFinal(e);
- match(b, d);
+ c1.init(Cipher.ENCRYPT_MODE, publicKey);
+ e = c1.doFinal(b);
+ c1.init(Cipher.DECRYPT_MODE, privateKey);
+ d = c1.doFinal(e);
+ match(b, d);
+ c2.init(Cipher.DECRYPT_MODE, privateKey);
+ d = c2.doFinal(e);
+ match(b, d);
- // invalid data
- c1.init(Cipher.DECRYPT_MODE, publicKey);
- try {
- d = c1.doFinal(e);
- throw new Exception("completed call");
- } catch (BadPaddingException ee) {
- ee.printStackTrace();
- }
+ // invalid data
+ c1.init(Cipher.DECRYPT_MODE, publicKey);
+ try {
+ d = c1.doFinal(e);
+ throw new Exception("completed call");
+ } catch (BadPaddingException ee) {
+ ee.printStackTrace();
+ }
- c1.init(Cipher.ENCRYPT_MODE, privateKey);
- e = c1.doFinal(b);
- c1.init(Cipher.DECRYPT_MODE, publicKey);
- d = c1.doFinal(e);
- match(b, d);
- c2.init(Cipher.DECRYPT_MODE, publicKey);
- d = c2.doFinal(e);
- match(b, d);
+ c1.init(Cipher.ENCRYPT_MODE, privateKey);
+ e = c1.doFinal(b);
+ c1.init(Cipher.DECRYPT_MODE, publicKey);
+ d = c1.doFinal(e);
+ match(b, d);
+ c2.init(Cipher.DECRYPT_MODE, publicKey);
+ d = c2.doFinal(e);
+ match(b, d);
- // reinit tests
- c1.init(Cipher.ENCRYPT_MODE, privateKey);
- c1.init(Cipher.ENCRYPT_MODE, privateKey);
- e = c1.doFinal(b);
- e = c1.doFinal(b);
- c1.update(b);
- c1.update(b);
- c1.init(Cipher.ENCRYPT_MODE, privateKey);
- e = c1.doFinal();
- e = c1.doFinal();
- c1.update(b);
- e = c1.doFinal();
+ // reinit tests
+ c1.init(Cipher.ENCRYPT_MODE, privateKey);
+ c1.init(Cipher.ENCRYPT_MODE, privateKey);
+ e = c1.doFinal(b);
+ e = c1.doFinal(b);
+ c1.update(b);
+ c1.update(b);
+ c1.init(Cipher.ENCRYPT_MODE, privateKey);
+ e = c1.doFinal();
+ e = c1.doFinal();
+ c1.update(b);
+ e = c1.doFinal();
- c1.update(new byte[256]);
- try {
- e = c1.doFinal();
- throw new Exception("completed call");
- } catch (IllegalBlockSizeException ee) {
- System.out.println(ee);
+ c1.update(new byte[256]);
+ try {
+ e = c1.doFinal();
+ throw new Exception("completed call");
+ } catch (IllegalBlockSizeException ee) {
+ System.out.println(ee);
+ }
}
-
}
private static void match(byte[] b1, byte[] b2) throws Exception {
--- a/jdk/test/sun/security/pkcs11/Cipher/TestRSACipherWrap.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestRSACipherWrap.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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,7 +23,7 @@
/**
* @test
- * @bug 6572331
+ * @bug 6572331 6994008
* @summary basic test for RSA cipher key wrapping functionality
* @author Valerie Peng
* @library ..
@@ -38,47 +38,48 @@
public class TestRSACipherWrap extends PKCS11Test {
- private static final String RSA_ALGO = "RSA/ECB/PKCS1Padding";
+ private static final String[] RSA_ALGOS =
+ { "RSA/ECB/PKCS1Padding", "RSA" };
public void main(Provider p) throws Exception {
try {
- Cipher.getInstance(RSA_ALGO, p);
+ Cipher.getInstance(RSA_ALGOS[0], p);
} catch (GeneralSecurityException e) {
- System.out.println("Not supported by provider, skipping");
+ System.out.println(RSA_ALGOS[0] + " unsupported, skipping");
return;
}
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", p);
kpg.initialize(1024);
KeyPair kp = kpg.generateKeyPair();
- PublicKey publicKey = kp.getPublic();
- PrivateKey privateKey = kp.getPrivate();
- Cipher cipherPKCS11 = Cipher.getInstance(RSA_ALGO, p);
- Cipher cipherJce = Cipher.getInstance(RSA_ALGO, "SunJCE");
+ for (String rsaAlgo: RSA_ALGOS) {
+ Cipher cipherPKCS11 = Cipher.getInstance(rsaAlgo, p);
+ Cipher cipherJce = Cipher.getInstance(rsaAlgo, "SunJCE");
- String algos[] = {"AES", "RC2", "Blowfish"};
- int keySizes[] = {128, 256};
+ String algos[] = {"AES", "RC2", "Blowfish"};
+ int keySizes[] = {128, 256};
- for (int j = 0; j < algos.length; j++) {
- String algorithm = algos[j];
- KeyGenerator keygen =
+ for (int j = 0; j < algos.length; j++) {
+ String algorithm = algos[j];
+ KeyGenerator keygen =
KeyGenerator.getInstance(algorithm);
- for (int i = 0; i < keySizes.length; i++) {
- SecretKey secretKey = null;
- System.out.print("Generate " + keySizes[i] + "-bit " +
+ for (int i = 0; i < keySizes.length; i++) {
+ SecretKey secretKey = null;
+ System.out.print("Generate " + keySizes[i] + "-bit " +
algorithm + " key using ");
- try {
- keygen.init(keySizes[i]);
- secretKey = keygen.generateKey();
- System.out.println(keygen.getProvider().getName());
- } catch (InvalidParameterException ipe) {
- secretKey = new SecretKeySpec(new byte[32], algorithm);
- System.out.println("SecretKeySpec class");
+ try {
+ keygen.init(keySizes[i]);
+ secretKey = keygen.generateKey();
+ System.out.println(keygen.getProvider().getName());
+ } catch (InvalidParameterException ipe) {
+ secretKey = new SecretKeySpec(new byte[32], algorithm);
+ System.out.println("SecretKeySpec class");
+ }
+ test(kp, secretKey, cipherPKCS11, cipherJce);
+ test(kp, secretKey, cipherPKCS11, cipherPKCS11);
+ test(kp, secretKey, cipherJce, cipherPKCS11);
}
- test(kp, secretKey, cipherPKCS11, cipherJce);
- test(kp, secretKey, cipherPKCS11, cipherPKCS11);
- test(kp, secretKey, cipherJce, cipherPKCS11);
}
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestRawRSACipher.java Mon Mar 07 14:48:27 2011 -0800
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 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
+ * 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 6994008
+ * @summary basic test for RSA/ECB/NoPadding cipher
+ * @author Valerie Peng
+ * @library ..
+ */
+
+import javax.crypto.*;
+import java.io.*;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.*;
+import java.util.*;
+
+public class TestRawRSACipher extends PKCS11Test {
+
+ public void main(Provider p) throws Exception {
+ try {
+ Cipher.getInstance("RSA/ECB/NoPadding", p);
+ } catch (GeneralSecurityException e) {
+ System.out.println("Not supported by provider, skipping");
+ return;
+ }
+
+ final int KEY_LEN = 1024;
+ KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", p);
+ kpGen.initialize(KEY_LEN);
+ KeyPair kp = kpGen.generateKeyPair();
+ Random random = new Random();
+ byte[] plainText, cipherText, recoveredText;
+ plainText = new byte[KEY_LEN/8];
+ random.nextBytes(plainText);
+ plainText[0] = 0; // to ensure that it's less than modulus
+
+ Cipher c1 = Cipher.getInstance("RSA/ECB/NoPadding", p);
+ Cipher c2 = Cipher.getInstance("RSA/ECB/NoPadding", "SunJCE");
+
+ c1.init(Cipher.ENCRYPT_MODE, kp.getPublic());
+ c2.init(Cipher.DECRYPT_MODE, kp.getPrivate());
+
+ cipherText = c1.doFinal(plainText);
+ recoveredText = c2.doFinal(cipherText);
+ if (!Arrays.equals(plainText, recoveredText)) {
+ throw new RuntimeException("E/D Test against SunJCE Failed!");
+ }
+
+ c2.init(Cipher.ENCRYPT_MODE, kp.getPublic());
+ c1.init(Cipher.DECRYPT_MODE, kp.getPrivate());
+ cipherText = c2.doFinal(plainText);
+ recoveredText = c1.doFinal(cipherText);
+ if (!Arrays.equals(plainText, recoveredText)) {
+ throw new RuntimeException("D/E Test against SunJCE Failed!");
+ }
+
+ System.out.println("Test Passed");
+ }
+
+ public static void main(String[] args) throws Exception {
+ main(new TestRawRSACipher());
+ }
+}
--- a/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphers.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphers.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 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,7 +23,7 @@
/**
* @test %I% %E%
- * @bug 4898461
+ * @bug 4898461 6604496
* @summary basic test for symmetric ciphers with padding
* @author Valerie Peng
* @library ..
@@ -70,9 +70,13 @@
new CI("DES/ECB/PKCS5Padding", "DES", 6400),
new CI("DESede/ECB/PKCS5Padding", "DESede", 400),
new CI("AES/ECB/PKCS5Padding", "AES", 64),
+
new CI("DES", "DES", 6400),
new CI("DESede", "DESede", 408),
- new CI("AES", "AES", 128)
+ new CI("AES", "AES", 128),
+
+ new CI("AES/CTR/NoPadding", "AES", 3200)
+
};
private static StringBuffer debugBuf = new StringBuffer();
--- a/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphersNoPad.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphersNoPad.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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,7 +23,7 @@
/**
* @test
- * @bug 4898484
+ * @bug 4898484 6604496
* @summary basic test for symmetric ciphers with no padding
* @author Valerie Peng
* @library ..
@@ -59,7 +59,8 @@
new CI("DES/CBC/NoPadding", "DES", 400),
new CI("DESede/CBC/NoPadding", "DESede", 160),
new CI("AES/CBC/NoPadding", "AES", 4800),
- new CI("Blowfish/CBC/NoPadding", "Blowfish", 24)
+ new CI("Blowfish/CBC/NoPadding", "Blowfish", 24),
+ new CI("AES/CTR/NoPadding", "AES", 1600)
};
private static StringBuffer debugBuf;
--- a/jdk/test/sun/security/tools/jarsigner/crl.sh Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/sun/security/tools/jarsigner/crl.sh Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 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
@@ -32,9 +32,6 @@
fi
# set platform-dependent variables
-# PF: platform name, say, solaris-sparc
-
-PF=""
OS=`uname -s`
case "$OS" in
@@ -47,54 +44,28 @@
esac
KS=crl.jks
-JFILE=crl.jar
KT="$TESTJAVA${FS}bin${FS}keytool -storepass changeit -keypass changeit -keystore $KS"
-JAR=$TESTJAVA${FS}bin${FS}jar
-JARSIGNER=$TESTJAVA${FS}bin${FS}jarsigner
-rm $KS $JFILE 2> /dev/null
+rm $KS 2> /dev/null
-# Generates some crl files, each containing two entries
+# Test keytool -gencrl
$KT -alias a -dname CN=a -keyalg rsa -genkey -validity 300
-$KT -alias a -gencrl -id 1:1 -id 2:2 -file crl1
-$KT -alias a -gencrl -id 3:3 -id 4:4 -file crl2
-$KT -alias b -dname CN=b -keyalg rsa -genkey -validity 300
-$KT -alias b -gencrl -id 5:1 -id 6:2 -file crl3
+$KT -alias a -gencrl -id 1:1 -id 2:2 -file crl1 || exit 1
+$KT -alias a -gencrl -id 3:3 -id 4:4 -file crl2 || exit 2
+$KT -alias a -gencrl -id 5:1 -id 6:2 -file crl3 || exit 4
-cat > ToURI.java <<EOF
-class ToURI {
- public static void main(String[] args) throws Exception {
- System.out.println(new java.io.File("crl1").toURI());
- }
-}
-EOF
-$TESTJAVA${FS}bin${FS}javac ToURI.java
-$TESTJAVA${FS}bin${FS}java ToURI > uri
-$KT -alias c -dname CN=c -keyalg rsa -genkey -validity 300 \
- -ext crl=uri:`cat uri`
-
-echo A > A
+# Test keytool -printcrl
-# Test -crl:auto, cRLDistributionPoints is a local file
+$KT -printcrl -file crl1 || exit 5
+$KT -printcrl -file crl2 || exit 6
+$KT -printcrl -file crl3 || exit 7
-$JAR cvf $JFILE A
-$JARSIGNER -keystore $KS -storepass changeit $JFILE c \
- -crl:auto || exit 1
-$JARSIGNER -keystore $KS -verify -debug -strict $JFILE || exit 6
-$KT -printcert -jarfile $JFILE | grep CRLs || exit 7
-
-# Test -crl <file>
-$JAR cvf $JFILE A
-$JARSIGNER -keystore $KS -storepass changeit $JFILE a \
- -crl crl1 -crl crl2 || exit 2
-$JARSIGNER -keystore $KS -storepass changeit $JFILE b \
- -crl crl3 -crl crl2 || exit 3
-$JARSIGNER -keystore $KS -verify -debug -strict $JFILE || exit 3
-$KT -printcert -jarfile $JFILE | grep CRLs || exit 4
-CRLCOUNT=`$KT -printcert -jarfile $JFILE | grep SerialNumber | wc -l`
-if [ $CRLCOUNT != 8 ]; then exit 5; fi
+# Test keytool -ext crl
+
+$KT -alias b -dname CN=c -keyalg rsa -genkey -validity 300 \
+ -ext crl=uri:http://www.example.com/crl || exit 10
exit 0
--- a/jdk/test/sun/security/tools/keytool/NewSize7.java Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/sun/security/tools/keytool/NewSize7.java Mon Mar 07 14:48:27 2011 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 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
@@ -29,6 +29,8 @@
import java.io.File;
import java.io.FileInputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.security.interfaces.RSAPublicKey;
@@ -42,8 +44,10 @@
" -alias a -dname cn=c -storepass changeit" +
" -keypass changeit -keyalg rsa").split(" "));
KeyStore ks = KeyStore.getInstance("JKS");
- ks.load(new FileInputStream(FILE), null);
- new File(FILE).delete();
+ try (FileInputStream fin = new FileInputStream(FILE)) {
+ ks.load(fin, null);
+ }
+ Files.delete(Paths.get(FILE));
RSAPublicKey r = (RSAPublicKey)ks.getCertificate("a").getPublicKey();
if (r.getModulus().bitLength() != 2048) {
throw new Exception("Bad keysize");
--- a/jdk/test/sun/tools/native2ascii/Native2AsciiTests.sh Mon Mar 07 14:46:16 2011 -0800
+++ b/jdk/test/sun/tools/native2ascii/Native2AsciiTests.sh Mon Mar 07 14:48:27 2011 -0800
@@ -24,7 +24,7 @@
#
# @test
-# @bug 4630463 4630971 4636448 4701617 4721296 4710890 6247817
+# @bug 4630463 4630971 4636448 4701617 4721296 4710890 6247817 7021987
# @summary Tests miscellaneous native2ascii bugfixes and regressions
@@ -100,6 +100,15 @@
$N2A -reverse -encoding MS932 $TESTSRC/A2N_4701617 x.out
check 4701617 $TESTSRC/A2N_4701617.expected x.out
+# Check that the inputfile appears in the error message when not found
+
+badin="DoesNotExist"
+$N2A $badin x.out | grep "$badin" > /dev/null
+if [ $? != 0 ]; then
+ echo "\"$badin\" expected to appear in error message"
+ exit 1
+fi
+
# for win32 only ensure when output file pre-exists that
# native2ascii tool will simply overwrite with the expected
# output file (fixed bugID 4710890)