From 8e2924170272d4ceda6720bdacd83212288ab08d Mon Sep 17 00:00:00 2001
From: Alan Bateman
Date: Mon, 21 Feb 2011 13:54:13 +0000
Subject: [PATCH 01/59] 7020517: (fs) FileStore.equals returns true if both
volumes have the same serial number
Reviewed-by: chegar
---
jdk/src/windows/classes/sun/nio/fs/WindowsFileStore.java | 5 ++---
jdk/test/java/nio/file/FileStore/Basic.java | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/jdk/src/windows/classes/sun/nio/fs/WindowsFileStore.java b/jdk/src/windows/classes/sun/nio/fs/WindowsFileStore.java
index 8b3c2fb4b19..07eb73231ce 100644
--- a/jdk/src/windows/classes/sun/nio/fs/WindowsFileStore.java
+++ b/jdk/src/windows/classes/sun/nio/fs/WindowsFileStore.java
@@ -201,13 +201,12 @@ class WindowsFileStore
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
diff --git a/jdk/test/java/nio/file/FileStore/Basic.java b/jdk/test/java/nio/file/FileStore/Basic.java
index f49bc6552bb..8a53ca4a47d 100644
--- a/jdk/test/java/nio/file/FileStore/Basic.java
+++ b/jdk/test/java/nio/file/FileStore/Basic.java
@@ -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 ..
*/
From 7ddd950b1d1868ddcf23c5c7033928ec572e674d Mon Sep 17 00:00:00 2001
From: Mike Duigou
Date: Mon, 21 Feb 2011 14:53:11 -0800
Subject: [PATCH 02/59] 7019705: Add -XX:+AggressiveOpts options to MOAT test
Reviewed-by: alanb
---
jdk/test/java/util/Collection/MOAT.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/jdk/test/java/util/Collection/MOAT.java b/jdk/test/java/util/Collection/MOAT.java
index a85afa3c8d2..ce7975635a8 100644
--- a/jdk/test/java/util/Collection/MOAT.java
+++ b/jdk/test/java/util/Collection/MOAT.java
@@ -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
From 53bff1223916557ba3b63a7b34c7b303a22542ed Mon Sep 17 00:00:00 2001
From: Masayoshi Okutsu
Date: Tue, 22 Feb 2011 14:51:43 +0900
Subject: [PATCH 03/59] 7010379: fontconfig update for RHEL 6
Reviewed-by: peytoia
---
jdk/make/sun/awt/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jdk/make/sun/awt/Makefile b/jdk/make/sun/awt/Makefile
index 7d8b4b6a6f1..18190f1c66c 100644
--- a/jdk/make/sun/awt/Makefile
+++ b/jdk/make/sun/awt/Makefile
@@ -368,7 +368,7 @@ else
FONTCONFIGS_SRC = $(CLOSED_SRC)/solaris/classes/sun/awt/fontconfigs
_FONTCONFIGS = \
fontconfig.properties \
- fontconfig.RedHat.properties \
+ fontconfig.RedHat.5.5.properties \
fontconfig.Turbo.properties \
fontconfig.SuSE.10.properties \
fontconfig.SuSE.11.properties
From 17cace4c588daf15aea08500ce4ac155ced224f1 Mon Sep 17 00:00:00 2001
From: Alan Bateman
Date: Tue, 22 Feb 2011 12:04:48 +0000
Subject: [PATCH 04/59] 7020888: (file) Miscellaneous and trivial clean-ups
(typos and opportunities to use suppressed exceptions)
Reviewed-by: mduigou, chegar
---
.../share/classes/java/io/BufferedReader.java | 13 ++++++++-----
.../share/classes/java/io/BufferedWriter.java | 17 ++++++++---------
jdk/src/share/classes/java/io/File.java | 2 +-
.../classes/java/io/FilterOutputStream.java | 7 +++----
.../classes/java/io/PushbackInputStream.java | 13 ++++++++-----
.../share/classes/java/io/PushbackReader.java | 7 +++++--
.../nio/channels/AsynchronousFileChannel.java | 4 ++--
.../java/nio/channels/SocketChannel.java | 9 ++++++---
.../classes/java/nio/file/CopyMoveHelper.java | 6 ++++--
jdk/src/share/classes/java/nio/file/Files.java | 15 ++++++++-------
.../classes/sun/nio/ch/FileChannelImpl.java | 4 ++--
...UnixAsynchronousServerSocketChannelImpl.java | 4 +++-
.../ch/UnixAsynchronousSocketChannelImpl.java | 9 ++++++---
jdk/test/java/lang/ProcessBuilder/Basic.java | 6 +++---
14 files changed, 67 insertions(+), 49 deletions(-)
diff --git a/jdk/src/share/classes/java/io/BufferedReader.java b/jdk/src/share/classes/java/io/BufferedReader.java
index e8583e046f0..45a71f5cf1c 100644
--- a/jdk/src/share/classes/java/io/BufferedReader.java
+++ b/jdk/src/share/classes/java/io/BufferedReader.java
@@ -512,11 +512,14 @@ public class BufferedReader extends Reader {
public void close() throws IOException {
synchronized (lock) {
- if (in == null)
- return;
- in.close();
- in = null;
- cb = null;
+ if (in != null) {
+ try {
+ in.close();
+ } finally {
+ in = null;
+ cb = null;
+ }
+ }
}
}
}
diff --git a/jdk/src/share/classes/java/io/BufferedWriter.java b/jdk/src/share/classes/java/io/BufferedWriter.java
index 4322683d367..fad7b44add4 100644
--- a/jdk/src/share/classes/java/io/BufferedWriter.java
+++ b/jdk/src/share/classes/java/io/BufferedWriter.java
@@ -255,17 +255,16 @@ public class BufferedWriter extends Writer {
}
}
+ @SuppressWarnings("try")
public void close() throws IOException {
synchronized (lock) {
- if (out == null) {
- return;
- }
- try {
- flushBuffer();
- } finally {
- out.close();
- out = null;
- cb = null;
+ if (out != null) {
+ try (Writer w = out) {
+ flushBuffer();
+ } finally {
+ out = null;
+ cb = null;
+ }
}
}
}
diff --git a/jdk/src/share/classes/java/io/File.java b/jdk/src/share/classes/java/io/File.java
index cde70d0b977..af198a5ed48 100644
--- a/jdk/src/share/classes/java/io/File.java
+++ b/jdk/src/share/classes/java/io/File.java
@@ -2055,7 +2055,7 @@ public class File
*
* @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})
*
diff --git a/jdk/src/share/classes/java/io/FilterOutputStream.java b/jdk/src/share/classes/java/io/FilterOutputStream.java
index 97154443a81..b7e920b1753 100644
--- a/jdk/src/share/classes/java/io/FilterOutputStream.java
+++ b/jdk/src/share/classes/java/io/FilterOutputStream.java
@@ -152,11 +152,10 @@ class FilterOutputStream extends OutputStream {
* @see java.io.FilterOutputStream#flush()
* @see java.io.FilterOutputStream#out
*/
+ @SuppressWarnings("try")
public void close() throws IOException {
- try {
- flush();
- } catch (IOException ignored) {
+ try (OutputStream ostream = out) {
+ flush();
}
- out.close();
}
}
diff --git a/jdk/src/share/classes/java/io/PushbackInputStream.java b/jdk/src/share/classes/java/io/PushbackInputStream.java
index a0e240f1d84..b6583f1dfb4 100644
--- a/jdk/src/share/classes/java/io/PushbackInputStream.java
+++ b/jdk/src/share/classes/java/io/PushbackInputStream.java
@@ -374,10 +374,13 @@ class PushbackInputStream extends FilterInputStream {
* @exception IOException if an I/O error occurs.
*/
public synchronized void close() throws IOException {
- if (in == null)
- return;
- in.close();
- in = null;
- buf = null;
+ if (in != null) {
+ try {
+ in.close();
+ } finally {
+ in = null;
+ buf = null;
+ }
+ }
}
}
diff --git a/jdk/src/share/classes/java/io/PushbackReader.java b/jdk/src/share/classes/java/io/PushbackReader.java
index 3add8a5d3f7..af44ee72fd3 100644
--- a/jdk/src/share/classes/java/io/PushbackReader.java
+++ b/jdk/src/share/classes/java/io/PushbackReader.java
@@ -245,8 +245,11 @@ public class PushbackReader extends FilterReader {
* @exception IOException If an I/O error occurs
*/
public void close() throws IOException {
- super.close();
- buf = null;
+ try {
+ super.close();
+ } finally {
+ buf = null;
+ }
}
/**
diff --git a/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java b/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java
index 1ca3417cce2..4f4ac7f4a36 100644
--- a/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java
+++ b/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java
@@ -53,7 +53,7 @@ import java.util.Collections;
* 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.
*
*
In addition to read and write operations, this class defines the
* following operations:
@@ -79,7 +79,7 @@ import java.util.Collections;
* 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.
*
diff --git a/jdk/src/share/classes/java/nio/channels/SocketChannel.java b/jdk/src/share/classes/java/nio/channels/SocketChannel.java
index fe044c4741d..b582c6d656a 100644
--- a/jdk/src/share/classes/java/nio/channels/SocketChannel.java
+++ b/jdk/src/share/classes/java/nio/channels/SocketChannel.java
@@ -182,10 +182,13 @@ public abstract class SocketChannel
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;
diff --git a/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java b/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java
index 70ca6ee50ad..54bfe085962 100644
--- a/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java
+++ b/jdk/src/share/classes/java/nio/file/CopyMoveHelper.java
@@ -135,11 +135,13 @@ class CopyMoveHelper {
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;
}
}
diff --git a/jdk/src/share/classes/java/nio/file/Files.java b/jdk/src/share/classes/java/nio/file/Files.java
index 357529ac9cf..e509440696b 100644
--- a/jdk/src/share/classes/java/nio/file/Files.java
+++ b/jdk/src/share/classes/java/nio/file/Files.java
@@ -129,17 +129,18 @@ public final class Files {
*
* 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);
*
*
* @param path
@@ -895,8 +896,8 @@ public final class Files {
/**
* 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}.
*
*
This method works in exactly the manner specified by {@link
* #createTempDirectory(Path,String,FileAttribute[])} method for the case
@@ -2583,7 +2584,7 @@ public final class Files {
* walkFileTree(start, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor)
*
* 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 +3006,7 @@ public final class Files {
* or after some bytes have been written to the file.
*
*
Usage example: 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:
*
* Path path = ...
diff --git a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java
index b15086eab12..c52fff788e9 100644
--- a/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java
+++ b/jdk/src/share/classes/sun/nio/ch/FileChannelImpl.java
@@ -475,8 +475,8 @@ public class FileChannelImpl
assert !target.isOpen();
try {
close();
- } catch (IOException ignore) {
- // nothing we can do
+ } catch (Throwable suppressed) {
+ e.addSuppressed(suppressed);
}
throw e;
} catch (IOException ioe) {
diff --git a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java
index 119146b68f4..ee3731a0c2e 100644
--- a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java
+++ b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousServerSocketChannelImpl.java
@@ -236,7 +236,9 @@ class UnixAsynchronousServerSocketChannelImpl
} catch (SecurityException x) {
try {
ch.close();
- } catch (IOException ignore) { }
+ } catch (Throwable suppressed) {
+ x.addSuppressed(suppressed);
+ }
throw x;
}
return ch;
diff --git a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java
index 4d887890ccd..13e4ad36434 100644
--- a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java
+++ b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java
@@ -255,10 +255,11 @@ class UnixAsynchronousSocketChannelImpl
// close channel if connection cannot be established
try {
close();
- } catch (IOException ignore) { }
+ } catch (Throwable suppressed) {
+ e.addSuppressed(suppressed);
+ }
}
-
// invoke handler and set result
CompletionHandler handler = connectHandler;
Object att = connectAttachment;
@@ -345,7 +346,9 @@ class UnixAsynchronousSocketChannelImpl
if (e != null) {
try {
close();
- } catch (IOException ignore) { }
+ } catch (Throwable suppressed) {
+ e.addSuppressed(suppressed);
+ }
}
if (handler == null) {
return CompletedFuture.withResult(null, e);
diff --git a/jdk/test/java/lang/ProcessBuilder/Basic.java b/jdk/test/java/lang/ProcessBuilder/Basic.java
index ebe65fb5bad..e109a4e78bd 100644
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java
@@ -1762,9 +1762,9 @@ public class Basic {
equal(p.exitValue(), 5);
- p.getInputStream().close();
- p.getErrorStream().close();
- p.getOutputStream().close();
+ try { p.getInputStream().close(); } catch (IOException ignore) { }
+ try {p.getErrorStream().close(); } catch (IOException ignore) { }
+ try { p.getOutputStream().close(); } catch (IOException ignore) { }
InputStream[] streams = { p.getInputStream(), p.getErrorStream() };
for (final InputStream in : streams) {
From 4c2006a7802d67d8da64c858eb4126ef0eb2381f Mon Sep 17 00:00:00 2001
From: Alan Bateman
Date: Tue, 22 Feb 2011 14:28:13 +0000
Subject: [PATCH 05/59] 7021327: Changes for 7020888 included changes to other
files in error
Reviewed-by: chegar
---
.../share/classes/java/io/BufferedReader.java | 13 +++++--------
.../share/classes/java/io/BufferedWriter.java | 17 +++++++++--------
.../classes/java/io/FilterOutputStream.java | 7 ++++---
.../classes/java/io/PushbackInputStream.java | 13 +++++--------
.../share/classes/java/io/PushbackReader.java | 7 ++-----
jdk/test/java/lang/ProcessBuilder/Basic.java | 6 +++---
6 files changed, 28 insertions(+), 35 deletions(-)
diff --git a/jdk/src/share/classes/java/io/BufferedReader.java b/jdk/src/share/classes/java/io/BufferedReader.java
index 45a71f5cf1c..e8583e046f0 100644
--- a/jdk/src/share/classes/java/io/BufferedReader.java
+++ b/jdk/src/share/classes/java/io/BufferedReader.java
@@ -512,14 +512,11 @@ public class BufferedReader extends Reader {
public void close() throws IOException {
synchronized (lock) {
- if (in != null) {
- try {
- in.close();
- } finally {
- in = null;
- cb = null;
- }
- }
+ if (in == null)
+ return;
+ in.close();
+ in = null;
+ cb = null;
}
}
}
diff --git a/jdk/src/share/classes/java/io/BufferedWriter.java b/jdk/src/share/classes/java/io/BufferedWriter.java
index fad7b44add4..4322683d367 100644
--- a/jdk/src/share/classes/java/io/BufferedWriter.java
+++ b/jdk/src/share/classes/java/io/BufferedWriter.java
@@ -255,16 +255,17 @@ public class BufferedWriter extends Writer {
}
}
- @SuppressWarnings("try")
public void close() throws IOException {
synchronized (lock) {
- if (out != null) {
- try (Writer w = out) {
- flushBuffer();
- } finally {
- out = null;
- cb = null;
- }
+ if (out == null) {
+ return;
+ }
+ try {
+ flushBuffer();
+ } finally {
+ out.close();
+ out = null;
+ cb = null;
}
}
}
diff --git a/jdk/src/share/classes/java/io/FilterOutputStream.java b/jdk/src/share/classes/java/io/FilterOutputStream.java
index b7e920b1753..97154443a81 100644
--- a/jdk/src/share/classes/java/io/FilterOutputStream.java
+++ b/jdk/src/share/classes/java/io/FilterOutputStream.java
@@ -152,10 +152,11 @@ class FilterOutputStream extends OutputStream {
* @see java.io.FilterOutputStream#flush()
* @see java.io.FilterOutputStream#out
*/
- @SuppressWarnings("try")
public void close() throws IOException {
- try (OutputStream ostream = out) {
- flush();
+ try {
+ flush();
+ } catch (IOException ignored) {
}
+ out.close();
}
}
diff --git a/jdk/src/share/classes/java/io/PushbackInputStream.java b/jdk/src/share/classes/java/io/PushbackInputStream.java
index b6583f1dfb4..a0e240f1d84 100644
--- a/jdk/src/share/classes/java/io/PushbackInputStream.java
+++ b/jdk/src/share/classes/java/io/PushbackInputStream.java
@@ -374,13 +374,10 @@ class PushbackInputStream extends FilterInputStream {
* @exception IOException if an I/O error occurs.
*/
public synchronized void close() throws IOException {
- if (in != null) {
- try {
- in.close();
- } finally {
- in = null;
- buf = null;
- }
- }
+ if (in == null)
+ return;
+ in.close();
+ in = null;
+ buf = null;
}
}
diff --git a/jdk/src/share/classes/java/io/PushbackReader.java b/jdk/src/share/classes/java/io/PushbackReader.java
index af44ee72fd3..3add8a5d3f7 100644
--- a/jdk/src/share/classes/java/io/PushbackReader.java
+++ b/jdk/src/share/classes/java/io/PushbackReader.java
@@ -245,11 +245,8 @@ public class PushbackReader extends FilterReader {
* @exception IOException If an I/O error occurs
*/
public void close() throws IOException {
- try {
- super.close();
- } finally {
- buf = null;
- }
+ super.close();
+ buf = null;
}
/**
diff --git a/jdk/test/java/lang/ProcessBuilder/Basic.java b/jdk/test/java/lang/ProcessBuilder/Basic.java
index e109a4e78bd..ebe65fb5bad 100644
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java
@@ -1762,9 +1762,9 @@ public class Basic {
equal(p.exitValue(), 5);
- try { p.getInputStream().close(); } catch (IOException ignore) { }
- try {p.getErrorStream().close(); } catch (IOException ignore) { }
- try { p.getOutputStream().close(); } catch (IOException ignore) { }
+ p.getInputStream().close();
+ p.getErrorStream().close();
+ p.getOutputStream().close();
InputStream[] streams = { p.getInputStream(), p.getErrorStream() };
for (final InputStream in : streams) {
From 7073df6b9666e9da3e635af0754377db577c9594 Mon Sep 17 00:00:00 2001
From: Michael McMahon
Date: Tue, 22 Feb 2011 14:44:43 +0000
Subject: [PATCH 06/59] 6702400: ChunkedInputStream expecting -1 from int read,
but int->char comparision is wrong
Reviewed-by: chegar
---
.../sun/net/httpserver/ChunkedInputStream.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java b/jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
index 97b8242a9fa..95e01018986 100644
--- a/jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
+++ b/jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
@@ -69,32 +69,33 @@ class ChunkedInputStream extends LeftOverInputStream {
*/
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;
}
}
}
From 4ce804890912ce7a0002c9e631c4dc699ac33c39 Mon Sep 17 00:00:00 2001
From: Valerie Peng
Date: Tue, 22 Feb 2011 12:01:35 -0800
Subject: [PATCH 07/59] 6604496: Support for CKM_AES_CTR (counter mode)
Enhanced SunPKCS11 provider to support AES/CTR/NoPadding transformation.
Reviewed-by: vinnie
---
.../sun/security/pkcs11/P11Cipher.java | 43 +++---
.../sun/security/pkcs11/SunPKCS11.java | 4 +-
.../pkcs11/wrapper/CK_AES_CTR_PARAMS.java | 66 ++++++++++
.../security/pkcs11/wrapper/CK_MECHANISM.java | 7 +-
.../pkcs11/wrapper/PKCS11Constants.java | 39 +++++-
.../sun/security/pkcs11/wrapper/p11_convert.c | 75 ++++++++++-
.../security/pkcs11/wrapper/pkcs-11v2-20a3.h | 124 ++++++++++++++++++
.../security/pkcs11/wrapper/pkcs11wrapper.h | 4 +-
.../pkcs11/Cipher/TestSymmCiphers.java | 10 +-
.../pkcs11/Cipher/TestSymmCiphersNoPad.java | 7 +-
10 files changed, 345 insertions(+), 34 deletions(-)
create mode 100644 jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS.java
create mode 100644 jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs-11v2-20a3.h
diff --git a/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java b/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java
index 3d2525f3f07..5257859e30e 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/P11Cipher.java
@@ -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 @@ import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
* 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 @@ final class P11Cipher extends CipherSpi {
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 @@ final class P11Cipher extends CipherSpi {
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 @@ final class P11Cipher extends CipherSpi {
("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 @@ final class P11Cipher extends CipherSpi {
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 @@ final class P11Cipher extends CipherSpi {
("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 @@ final class P11Cipher extends CipherSpi {
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
diff --git a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
index 55843b95c58..d1a1db3defd 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
@@ -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,6 +621,8 @@ public final class SunPKCS11 extends AuthProvider {
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));
diff --git a/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS.java b/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS.java
new file mode 100644
index 00000000000..7208f481c2a
--- /dev/null
+++ b/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_AES_CTR_PARAMS.java
@@ -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.
+ *
+ * @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();
+ }
+}
diff --git a/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java b/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java
index b84c5e99c15..3322d19b00c 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/wrapper/CK_MECHANISM.java
@@ -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 @@ public class CK_MECHANISM {
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;
diff --git a/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java b/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java
index f5bf7f1034d..98e9fe0651b 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/wrapper/PKCS11Constants.java
@@ -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 interface PKCS11Constants {
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 interface PKCS11Constants {
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 @@ public interface PKCS11Constants {
/* 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;
diff --git a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
index 4abc1507388..c32a278b585 100644
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/p11_convert.c
@@ -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.
@@ -694,6 +694,46 @@ CK_SSL3_KEY_MAT_PARAMS jSsl3KeyMatParamToCKSsl3KeyMatParam(JNIEnv *env, jobject
return ckParam ;
}
+/*
+ * 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
*
@@ -937,12 +977,10 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam,
{
/* 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 @@ void jMechanismParameterToCKMechanismParameterSlow(JNIEnv *env, jobject jParam,
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)) {
diff --git a/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs-11v2-20a3.h b/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs-11v2-20a3.h
new file mode 100644
index 00000000000..0486fdf6a63
--- /dev/null
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs-11v2-20a3.h
@@ -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
diff --git a/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h b/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
index 98598d807f5..ff6d550d523 100644
--- a/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
+++ b/jdk/src/share/native/sun/security/pkcs11/wrapper/pkcs11wrapper.h
@@ -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
#include
@@ -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
diff --git a/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphers.java b/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphers.java
index b8a6dcced66..14e41cdddd2 100644
--- a/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphers.java
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphers.java
@@ -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 @@ public class TestSymmCiphers extends PKCS11Test {
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();
diff --git a/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphersNoPad.java b/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphersNoPad.java
index 5c2e939e8bd..5f94ea48f57 100644
--- a/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphersNoPad.java
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestSymmCiphersNoPad.java
@@ -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 @@ public class TestSymmCiphersNoPad extends PKCS11Test {
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;
From dd0e38d73ab8832a7c0e72d269327739d158901d Mon Sep 17 00:00:00 2001
From: Stuart Marks
Date: Tue, 22 Feb 2011 15:34:17 -0800
Subject: [PATCH 08/59] 7021209: convert lang, math, util to use
try-with-resources
Reviewed-by: alanb, darcy, naoto
---
jdk/src/share/classes/java/lang/Package.java | 10 +--
jdk/src/share/classes/java/util/Currency.java | 4 +-
.../util/calendar/LocalGregorianCalendar.java | 4 +-
.../util/prefs/FileSystemPreferences.java | 12 +--
jdk/test/java/lang/Character/CheckScript.java | 47 +++++-----
.../lang/Runtime/shutdown/ShutdownHooks.java | 10 +--
.../lang/instrument/BootClassPath/Setup.java | 34 ++++----
.../java/lang/instrument/ilib/Inject.java | 29 ++++---
.../java/math/BigInteger/BigIntegerTest.java | 49 +++--------
.../java/util/Currency/ValidateISO4217.java | 87 ++++++++++---------
.../util/Formatter/FailingConstructors.java | 5 +-
.../java/util/Locale/LocaleEnhanceTest.java | 10 +--
.../java/util/ResourceBundle/Bug6204853.java | 19 ++--
.../util/Scanner/FailingConstructors.java | 5 +-
14 files changed, 150 insertions(+), 175 deletions(-)
diff --git a/jdk/src/share/classes/java/lang/Package.java b/jdk/src/share/classes/java/lang/Package.java
index 99db6944c92..75bb658af44 100644
--- a/jdk/src/share/classes/java/lang/Package.java
+++ b/jdk/src/share/classes/java/lang/Package.java
@@ -576,12 +576,10 @@ public class Package implements java.lang.reflect.AnnotatedElement {
* 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;
}
diff --git a/jdk/src/share/classes/java/util/Currency.java b/jdk/src/share/classes/java/util/Currency.java
index b3058053afa..e9ce7005df6 100644
--- a/jdk/src/share/classes/java/util/Currency.java
+++ b/jdk/src/share/classes/java/util/Currency.java
@@ -233,7 +233,9 @@ public final class Currency implements Serializable {
"currency.properties");
if (propFile.exists()) {
Properties props = new Properties();
- props.load(new FileReader(propFile));
+ try (FileReader fr = new FileReader(propFile)) {
+ props.load(fr);
+ }
Set keys = props.stringPropertyNames();
Pattern propertiesPattern =
Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])");
diff --git a/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java b/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java
index 6710dbae3bc..de5f749608c 100644
--- a/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java
+++ b/jdk/src/share/classes/sun/util/calendar/LocalGregorianCalendar.java
@@ -127,7 +127,9 @@ public class LocalGregorianCalendar extends BaseCalendar {
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;
}
});
diff --git a/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java b/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java
index 32e4b032929..53a19b5f5bd 100644
--- a/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java
+++ b/jdk/src/solaris/classes/java/util/prefs/FileSystemPreferences.java
@@ -571,9 +571,9 @@ class FileSystemPreferences extends AbstractPreferences {
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 @@ class FileSystemPreferences extends AbstractPreferences {
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);
diff --git a/jdk/test/java/lang/Character/CheckScript.java b/jdk/test/java/lang/Character/CheckScript.java
index a286643c8cf..6d0f650d169 100644
--- a/jdk/test/java/lang/Character/CheckScript.java
+++ b/jdk/test/java/lang/Character/CheckScript.java
@@ -12,40 +12,43 @@ import java.lang.Character.UnicodeScript;
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> 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 ranges = scripts.get(name);
- if (ranges == null) {
- ranges = new ArrayList();
- scripts.put(name, ranges);
+ try (BufferedReader sbfr = open(args)) {
+ 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 ranges = scripts.get(name);
+ if (ranges == null) {
+ ranges = new ArrayList();
+ scripts.put(name, ranges);
+ }
+ ranges.add(start);
+ ranges.add(end);
}
- ranges.add(start);
- ranges.add(end);
}
}
- sbfr.close();
// check all defined ranges
Integer[] ZEROSIZEARRAY = new Integer[0];
for (String name : scripts.keySet()) {
diff --git a/jdk/test/java/lang/Runtime/shutdown/ShutdownHooks.java b/jdk/test/java/lang/Runtime/shutdown/ShutdownHooks.java
index a198d98b872..bfe2b60e3ee 100644
--- a/jdk/test/java/lang/Runtime/shutdown/ShutdownHooks.java
+++ b/jdk/test/java/lang/Runtime/shutdown/ShutdownHooks.java
@@ -43,9 +43,9 @@ public class ShutdownHooks {
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 @@ public class ShutdownHooks {
// 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);
}
diff --git a/jdk/test/java/lang/instrument/BootClassPath/Setup.java b/jdk/test/java/lang/instrument/BootClassPath/Setup.java
index 90beff135ea..3ef40f13217 100644
--- a/jdk/test/java/lang/instrument/BootClassPath/Setup.java
+++ b/jdk/test/java/lang/instrument/BootClassPath/Setup.java
@@ -62,31 +62,33 @@ public class Setup {
* 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 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 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) {
diff --git a/jdk/test/java/math/BigInteger/BigIntegerTest.java b/jdk/test/java/math/BigInteger/BigIntegerTest.java
index ba35c7bbdbe..c23563f2208 100644
--- a/jdk/test/java/math/BigInteger/BigIntegerTest.java
+++ b/jdk/test/java/math/BigInteger/BigIntegerTest.java
@@ -645,26 +645,17 @@ public class BigIntegerTest {
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 @@ public class BigIntegerTest {
System.err.println("Serialized failed for hex " +
b1.toString(16));
}
- } finally {
- fos.close();
}
f.delete();
}
@@ -683,29 +672,17 @@ public class BigIntegerTest {
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) ||
diff --git a/jdk/test/java/util/Currency/ValidateISO4217.java b/jdk/test/java/util/Currency/ValidateISO4217.java
index c92b06226fe..486741fdd2c 100644
--- a/jdk/test/java/util/Currency/ValidateISO4217.java
+++ b/jdk/test/java/util/Currency/ValidateISO4217.java
@@ -111,57 +111,58 @@ public class ValidateISO4217 {
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]);
diff --git a/jdk/test/java/util/Formatter/FailingConstructors.java b/jdk/test/java/util/Formatter/FailingConstructors.java
index 8ef99f146a4..29e34bc179e 100644
--- a/jdk/test/java/util/Formatter/FailingConstructors.java
+++ b/jdk/test/java/util/Formatter/FailingConstructors.java
@@ -34,6 +34,7 @@ import java.io.FileOutputStream;
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 @@ public class FailingConstructors {
/* 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();
diff --git a/jdk/test/java/util/Locale/LocaleEnhanceTest.java b/jdk/test/java/util/Locale/LocaleEnhanceTest.java
index f7ed5ab3dfb..1a5e9b5e418 100644
--- a/jdk/test/java/util/Locale/LocaleEnhanceTest.java
+++ b/jdk/test/java/util/Locale/LocaleEnhanceTest.java
@@ -1187,14 +1187,12 @@ public class LocaleEnhanceTest extends LocaleTestFmwk {
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());
}
diff --git a/jdk/test/java/util/ResourceBundle/Bug6204853.java b/jdk/test/java/util/ResourceBundle/Bug6204853.java
index ca13fa65015..4ba5386c8e5 100644
--- a/jdk/test/java/util/ResourceBundle/Bug6204853.java
+++ b/jdk/test/java/util/ResourceBundle/Bug6204853.java
@@ -39,24 +39,19 @@ import java.util.PropertyResourceBundle;
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.");
}
diff --git a/jdk/test/java/util/Scanner/FailingConstructors.java b/jdk/test/java/util/Scanner/FailingConstructors.java
index 476c000ae1a..d74f5c79cc4 100644
--- a/jdk/test/java/util/Scanner/FailingConstructors.java
+++ b/jdk/test/java/util/Scanner/FailingConstructors.java
@@ -33,6 +33,7 @@ import java.io.FileInputStream;
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 @@ public class FailingConstructors {
/* 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();
From 66ca7600c46c11809b4324c4163a0ed8e92b1651 Mon Sep 17 00:00:00 2001
From: Masayoshi Okutsu
Date: Wed, 23 Feb 2011 14:09:23 +0900
Subject: [PATCH 09/59] 6623219: Font.canDisplayUpTo does not work with
supplementary characters
Reviewed-by: prr, peytoia
---
jdk/src/share/classes/java/awt/Font.java | 61 ++++++++--
.../SupplementaryCanDisplayUpToTest.java | 105 ++++++++++++++++++
2 files changed, 154 insertions(+), 12 deletions(-)
create mode 100644 jdk/test/java/awt/FontClass/SurrogateTest/SupplementaryCanDisplayUpToTest.java
diff --git a/jdk/src/share/classes/java/awt/Font.java b/jdk/src/share/classes/java/awt/Font.java
index 051ec7fa578..73585e46f9f 100644
--- a/jdk/src/share/classes/java/awt/Font.java
+++ b/jdk/src/share/classes/java/awt/Font.java
@@ -1985,8 +1985,22 @@ public class Font implements java.io.Serializable
* @since 1.2
*/
public int canDisplayUpTo(String str) {
- return canDisplayUpTo(new StringCharacterIterator(str), 0,
- str.length());
+ Font2D font2d = getFont2D();
+ int len = str.length();
+ for (int i = 0; i < len; i++) {
+ char c = str.charAt(i);
+ if (font2d.canDisplay(c)) {
+ continue;
+ }
+ if (!Character.isHighSurrogate(c)) {
+ return i;
+ }
+ if (!font2d.canDisplay(str.codePointAt(i))) {
+ return i;
+ }
+ i++;
+ }
+ return -1;
}
/**
@@ -2009,11 +2023,21 @@ public class Font implements java.io.Serializable
* @since 1.2
*/
public int canDisplayUpTo(char[] text, int start, int limit) {
- while (start < limit && canDisplay(text[start])) {
- ++start;
+ Font2D font2d = getFont2D();
+ for (int i = start; i < limit; i++) {
+ char c = text[i];
+ if (font2d.canDisplay(c)) {
+ continue;
+ }
+ if (!Character.isHighSurrogate(c)) {
+ return i;
+ }
+ if (!font2d.canDisplay(Character.codePointAt(text, i, limit))) {
+ return i;
+ }
+ i++;
}
-
- return start == limit ? -1 : start;
+ return -1;
}
/**
@@ -2034,13 +2058,26 @@ public class Font implements java.io.Serializable
* @since 1.2
*/
public int canDisplayUpTo(CharacterIterator iter, int start, int limit) {
- for (char c = iter.setIndex(start);
- iter.getIndex() < limit && canDisplay(c);
- c = iter.next()) {
+ Font2D font2d = getFont2D();
+ char c = iter.setIndex(start);
+ for (int i = start; i < limit; i++, c = iter.next()) {
+ if (font2d.canDisplay(c)) {
+ continue;
+ }
+ if (!Character.isHighSurrogate(c)) {
+ return i;
+ }
+ char c2 = iter.next();
+ // c2 could be CharacterIterator.DONE which is not a low surrogate.
+ if (!Character.isLowSurrogate(c2)) {
+ return i;
+ }
+ if (!font2d.canDisplay(Character.toCodePoint(c, c2))) {
+ return i;
+ }
+ i++;
}
-
- int result = iter.getIndex();
- return result == limit ? -1 : result;
+ return -1;
}
/**
diff --git a/jdk/test/java/awt/FontClass/SurrogateTest/SupplementaryCanDisplayUpToTest.java b/jdk/test/java/awt/FontClass/SurrogateTest/SupplementaryCanDisplayUpToTest.java
new file mode 100644
index 00000000000..1fd09e4b068
--- /dev/null
+++ b/jdk/test/java/awt/FontClass/SurrogateTest/SupplementaryCanDisplayUpToTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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 6623219
+ * @summary Test canDisplayUpTo with supplementary characters.
+ */
+
+import java.awt.*;
+import java.text.*;
+
+public class SupplementaryCanDisplayUpToTest {
+ // Lists consisting of a font name, test text, and its expected
+ // return value. Test text uses private area code point U+F0000
+ // (\udb80\udc00).
+ private static String[][] DATA = {
+ // Windows
+ { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80\udc00", "4" },
+ { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80Z", "4" },
+ { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80", "4" },
+ { "Meiryo", "\ud87e\udd45\ud87e\udd47\udc00", "4" },
+ { "Meiryo", "\ud87e\udd45\ud87e\udd47", "-1" },
+
+ // Linux
+ { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },
+ { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },
+ { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },
+ { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },
+ { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b", "-1" },
+
+ // Solaris
+ { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },
+ { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },
+ { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },
+ { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },
+ { "FZMingTi", "\ud87e\udc25\ud87e\udc3b", "-1" },
+ };
+ private static int errorcount = 0;
+
+ public static void main(String[] args) {
+ for (String[] data : DATA) {
+ String fontname = data[0];
+ Font font = new Font(fontname, Font.PLAIN, 16);
+ if (font.getFamily().equals(Font.DIALOG)) {
+ // Skip any unavailable fonts.
+ continue;
+ }
+
+ System.out.printf("Testing with font '%s'... ", fontname);
+ int errors = 0;
+ String text = data[1];
+ int expected = Integer.parseInt(data[2]);
+
+ int result = font.canDisplayUpTo(text);
+ if (result != expected) {
+ System.err.println("canDisplayUpTo(String) returns " + result);
+ errors++;
+ }
+
+ result = font.canDisplayUpTo(text.toCharArray(), 0, text.length());
+ if (result != expected) {
+ System.err.println("canDisplayUpTo(char[], int, int) returns " + result);
+ errors++;
+ }
+
+ CharacterIterator iter = new StringCharacterIterator(text);
+ result = font.canDisplayUpTo(iter, iter.getBeginIndex(), iter.getEndIndex());
+ if (result != expected) {
+ System.err.println("canDisplayUpTo(CharacterIterator, int, int) returns " + result);
+ errors++;
+ }
+
+ if (errors == 0) {
+ System.out.println("passed");
+ } else {
+ System.out.println("failed");
+ errorcount += errors;
+ }
+ }
+ if (errorcount > 0) {
+ throw new RuntimeException("SupplementaryCanDisplayUpToTest: failed");
+ }
+ }
+}
From 7e8c6fd47b9675e68d784549794b3bf1340f9de5 Mon Sep 17 00:00:00 2001
From: Masayoshi Okutsu
Date: Wed, 23 Feb 2011 16:50:13 +0900
Subject: [PATCH 10/59] 6955047: (tz) javadoc for
TimeZone.getDisplayName(boolean daylight, int style, Locale locale) is not
clear 7021680: (tz) daylight savings time should be daylight saving time
Reviewed-by: peytoia
---
jdk/src/share/classes/java/util/Calendar.java | 4 +--
.../classes/java/util/GregorianCalendar.java | 4 +--
jdk/src/share/classes/java/util/TimeZone.java | 28 +++++++++++--------
3 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/jdk/src/share/classes/java/util/Calendar.java b/jdk/src/share/classes/java/util/Calendar.java
index 70460eaec07..897a891cbe8 100644
--- a/jdk/src/share/classes/java/util/Calendar.java
+++ b/jdk/src/share/classes/java/util/Calendar.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -554,7 +554,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparableget and set indicating the
- * daylight savings offset in milliseconds.
+ * daylight saving offset in milliseconds.
*
* This field reflects the correct daylight saving offset value of
* the time zone of this Calendar if the
diff --git a/jdk/src/share/classes/java/util/GregorianCalendar.java b/jdk/src/share/classes/java/util/GregorianCalendar.java
index 75402f0ff65..3a6d203256a 100644
--- a/jdk/src/share/classes/java/util/GregorianCalendar.java
+++ b/jdk/src/share/classes/java/util/GregorianCalendar.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 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
@@ -260,7 +260,7 @@ import sun.util.calendar.ZoneInfo;
* // create a Pacific Standard Time time zone
* SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
*
- * // set up rules for daylight savings time
+ * // set up rules for Daylight Saving Time
* pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
* pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
*
diff --git a/jdk/src/share/classes/java/util/TimeZone.java b/jdk/src/share/classes/java/util/TimeZone.java
index 9799be601fe..266f627d7e2 100644
--- a/jdk/src/share/classes/java/util/TimeZone.java
+++ b/jdk/src/share/classes/java/util/TimeZone.java
@@ -339,8 +339,9 @@ abstract public class TimeZone implements Serializable, Cloneable {
/**
* Returns a name in the specified {@code style} of this {@code TimeZone}
* suitable for presentation to the user in the default locale. If the
- * specified {@code daylight} is {@code true}, a daylight saving time name
- * is returned. Otherwise, a standard time name is returned.
+ * specified {@code daylight} is {@code true}, a Daylight Saving Time name
+ * is returned (even if this {@code TimeZone} doesn't observe Daylight Saving
+ * Time). Otherwise, a Standard Time name is returned.
*
*
This method is equivalent to:
*
@@ -348,7 +349,8 @@ abstract public class TimeZone implements Serializable, Cloneable {
* Locale.getDefault({@link Locale.Category#DISPLAY}))
*
*
- * @param daylight if {@code true}, return the daylight saving time name.
+ * @param daylight {@code true} specifying a Daylight Saving Time name, or
+ * {@code false} specifying a Standard Time name
* @param style either {@link #LONG} or {@link #SHORT}
* @return the human-readable name of this time zone in the default locale.
* @exception IllegalArgumentException if {@code style} is invalid.
@@ -356,6 +358,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
* @see #getDisplayName(boolean, int, Locale)
* @see Locale#getDefault(Locale.Category)
* @see Locale.Category
+ * @see java.text.DateFormatSymbols#getZoneStrings()
*/
public final String getDisplayName(boolean daylight, int style) {
return getDisplayName(daylight, style,
@@ -365,8 +368,9 @@ abstract public class TimeZone implements Serializable, Cloneable {
/**
* Returns a name in the specified {@code style} of this {@code TimeZone}
* suitable for presentation to the user in the specified {@code
- * locale}. If the specified {@code daylight} is {@code true}, a daylight
- * saving time name is returned. Otherwise, a standard time name is
+ * locale}. If the specified {@code daylight} is {@code true}, a Daylight
+ * Saving Time name is returned (even if this {@code TimeZone} doesn't
+ * observe Daylight Saving Time). Otherwise, a Standard Time name is
* returned.
*
*
When looking up a time zone name, the {@linkplain
@@ -379,13 +383,15 @@ abstract public class TimeZone implements Serializable, Cloneable {
* found, the name is returned. Otherwise, a string in the
* normalized custom ID format is returned.
*
- * @param daylight if {@code true}, return the daylight saving time name.
+ * @param daylight {@code true} specifying a Daylight Saving Time name, or
+ * {@code false} specifying a Standard Time name
* @param style either {@link #LONG} or {@link #SHORT}
- * @param locale the locale in which to supply the display name.
+ * @param locale the locale in which to supply the display name.
* @return the human-readable name of this time zone in the given locale.
* @exception IllegalArgumentException if {@code style} is invalid.
* @exception NullPointerException if {@code locale} is {@code null}.
* @since 1.2
+ * @see java.text.DateFormatSymbols#getZoneStrings()
*/
public String getDisplayName(boolean daylight, int style, Locale locale) {
if (style != SHORT && style != LONG) {
@@ -526,10 +532,10 @@ abstract public class TimeZone implements Serializable, Cloneable {
/**
* Queries if the given {@code date} is in Daylight Saving Time in
- * this {@code TimeZone}.
+ * this time zone.
*
- * @param date the given {@code Date}.
- * @return {@code true} if the given {@code date} is in Daylight Saving Time,
+ * @param date the given Date.
+ * @return {@code true} if the given date is in Daylight Saving Time,
* {@code false}, otherwise.
*/
abstract public boolean inDaylightTime(Date date);
@@ -566,7 +572,7 @@ abstract public class TimeZone implements Serializable, Cloneable {
* @param rawOffset the given time zone GMT offset in milliseconds.
* @return an array of IDs, where the time zone for that ID has
* the specified GMT offset. For example, "America/Phoenix" and "America/Denver"
- * both have GMT-07:00, but differ in daylight savings behavior.
+ * both have GMT-07:00, but differ in daylight saving behavior.
* @see #getRawOffset()
*/
public static synchronized String[] getAvailableIDs(int rawOffset) {
From ad3d04a30c217367c574e22f0d09789df587285e Mon Sep 17 00:00:00 2001
From: Doug Lea
Date: Wed, 23 Feb 2011 14:56:44 +0000
Subject: [PATCH 11/59] 7017493: ConcurrentLinkedDeque: Unexpected
initialization order can lead to crash due to use of Unsafe
Reviewed-by: chegar
---
.../concurrent/ConcurrentLinkedDeque.java | 71 +++++++++-------
.../concurrent/ConcurrentLinkedQueue.java | 52 +++++++-----
.../concurrent/ConcurrentSkipListMap.java | 61 +++++++++-----
.../concurrent/ConcurrentSkipListSet.java | 20 +++--
.../util/concurrent/CopyOnWriteArrayList.java | 19 +++--
.../util/concurrent/LinkedTransferQueue.java | 60 +++++++------
.../classes/java/util/concurrent/Phaser.java | 20 ++---
.../concurrent/PriorityBlockingQueue.java | 23 ++---
.../util/concurrent/SynchronousQueue.java | 84 ++++++++++++++-----
9 files changed, 245 insertions(+), 165 deletions(-)
diff --git a/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java b/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
index 2158084f9f9..1030fac0423 100644
--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java
@@ -272,13 +272,6 @@ public class ConcurrentLinkedDeque
private static final Node
*
*
Otherwise the new URI's authority component is copied from
- * this URI, and its path is computed as follows:
+ * this URI, and its path is computed as follows:
*
*
*
@@ -1005,7 +1005,7 @@ public final class URI
* path and then normalizing the result as if by invoking the {@link
* #normalize() normalize} method.
*
- *
+ *
*
*
*
@@ -1511,7 +1511,7 @@ public final class URI
* fragments.
*
*
Two hierarchical URIs with identical schemes are ordered
- * according to the ordering of their authority components:
+ * according to the ordering of their authority components:
*
*
*
@@ -1526,7 +1526,7 @@ public final class URI
* the URIs are ordered according to the ordering of their authority
* components.
*
- *
+ *
*
*
Finally, two hierarchical URIs with identical schemes and
* authority components are ordered according to the ordering of their
diff --git a/jdk/src/share/classes/java/net/package.html b/jdk/src/share/classes/java/net/package.html
index 7c7058d7b1c..12dfe9803d0 100644
--- a/jdk/src/share/classes/java/net/package.html
+++ b/jdk/src/share/classes/java/net/package.html
@@ -31,18 +31,18 @@ Provides the classes for implementing networking applications.
The java.net package can be roughly divided in two sections:
-
A Low Level API, which deals with the following abstractions:
+
A Low Level API, which deals with the following abstractions:
Addresses, which are networking identifiers, like IP addresses.
Sockets, which are basic bidirectional data communication mechanisms.
Interfaces, which describe network interfaces.
-
-
A High Level API, which deals with the following abstractions:
+
+
A High Level API, which deals with the following abstractions:
URIs, which represent Universal Resource Identifiers.
URLs, which represent Universal Resource Locators.
Connections, which represents connections to the resource pointed to by URLs.
-
+
Addresses
Addresses are used throughout the java.net APIs as either host identifiers, or socket endpoint identifiers.
From 23ff61a1ff627571961fc5ecaa6dfeeaf1f5ea0e Mon Sep 17 00:00:00 2001
From: Chris Hegarty
Date: Thu, 3 Mar 2011 16:48:53 +0000
Subject: [PATCH 46/59] 6721694: java/lang/Thread/StartOOMTest.java fails with
timeout or with crash
The test is not suitable to be run automatically
Reviewed-by: alanb
---
jdk/test/java/lang/Thread/StartOOMTest.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/jdk/test/java/lang/Thread/StartOOMTest.java b/jdk/test/java/lang/Thread/StartOOMTest.java
index fd6c070baef..57edd723c31 100644
--- a/jdk/test/java/lang/Thread/StartOOMTest.java
+++ b/jdk/test/java/lang/Thread/StartOOMTest.java
@@ -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.*;
From 75bd2accd370d72ffa4ee37ef779e81bedccfad7 Mon Sep 17 00:00:00 2001
From: Sean Coffey
Date: Thu, 3 Mar 2011 16:51:03 +0000
Subject: [PATCH 47/59] 6750362: Very large LDAP requests throw a OOM on LDAP
servers which aren't aware of Paged Results Controls 6748156: add an new JNDI
property to control the boolean flag WaitForReply
Reviewed-by: vinnie, robm
---
.../classes/com/sun/jndi/ldap/Connection.java | 16 ++-
.../classes/com/sun/jndi/ldap/LdapClient.java | 8 +-
.../classes/com/sun/jndi/ldap/LdapCtx.java | 65 +++++++++-
.../com/sun/jndi/ldap/LdapRequest.java | 49 ++++++--
.../com/sun/jndi/ldap/NoWaitForReplyTest.java | 118 ++++++++++++++++++
5 files changed, 231 insertions(+), 25 deletions(-)
create mode 100644 jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java
diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java b/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java
index 94067617ae1..6ca3ae1d85a 100644
--- a/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/Connection.java
@@ -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 @@ public final class Connection implements Runnable {
}
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) {
diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java b/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java
index 99f84c0adb3..41a3dfba14b 100644
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapClient.java
@@ -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 @@ public final class LdapClient implements PooledConnection {
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 @@ public final class LdapClient implements PooledConnection {
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
diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java b/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java
index e50ebc0d17a..68b272e10e5 100644
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapCtx.java
@@ -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 @@ final public class LdapCtx extends ComponentDirContext
// 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 @@ final public class LdapCtx extends ComponentDirContext
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 @@ final public class LdapCtx extends ComponentDirContext
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 @@ final public class LdapCtx extends ComponentDirContext
}
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 @@ final public class LdapCtx extends ComponentDirContext
batchSize,
reqCtls,
binaryAttrs,
- waitFirstReply);
+ waitForReply,
+ replyQueueSize);
respCtls = answer.resControls; // retrieve response controls
return answer;
@@ -2170,6 +2181,10 @@ final public class LdapCtx extends ComponentDirContext
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 @@ final public class LdapCtx extends ComponentDirContext
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 @@ final public class LdapCtx extends ComponentDirContext
// 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
}
@@ -2441,6 +2468,34 @@ final public class LdapCtx extends ComponentDirContext
}
}
+ /**
+ * 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
*/
diff --git a/jdk/src/share/classes/com/sun/jndi/ldap/LdapRequest.java b/jdk/src/share/classes/com/sun/jndi/ldap/LdapRequest.java
index 2f8e39e5724..23347ac5dc8 100644
--- a/jdk/src/share/classes/com/sun/jndi/ldap/LdapRequest.java
+++ b/jdk/src/share/classes/com/sun/jndi/ldap/LdapRequest.java
@@ -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 @@ final class LdapRequest {
int msgId; // read-only
private int gotten = 0;
- private Vector replies = new Vector(3);
+ private BlockingQueue 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();
+ } else {
+ this.replies =
+ new LinkedBlockingQueue(replyQueueCapacity);
+ highWatermark = (replyQueueCapacity * 80) / 100; // 80% capacity
+ }
}
synchronized void cancel() {
@@ -57,7 +70,13 @@ final class LdapRequest {
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 @@ final class LdapRequest {
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 @@ final class LdapRequest {
" 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() {
diff --git a/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java b/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java
new file mode 100644
index 00000000000..4a93ef41ff8
--- /dev/null
+++ b/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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;
+
+ // Set up the environment for creating the initial context
+ Hashtable env = new Hashtable(11);
+ env.put(Context.PROVIDER_URL, "ldap://localhost:22001");
+ 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");
+
+ DummyServer ldapServer = new DummyServer();
+
+ try {
+
+ // start the LDAP server
+ ldapServer.start();
+
+ // 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 {
+
+ static int serverPort = 22001;
+
+ DummyServer() {
+ }
+
+ public void run() {
+ try {
+ ServerSocket serverSock = new ServerSocket(serverPort);
+ Socket socket = serverSock.accept();
+ System.out.println("Server: accepted a connection");
+ BufferedInputStream bin =
+ new BufferedInputStream(socket.getInputStream());
+
+ while (true) {
+ bin.read();
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+}
+}
From 9d85a7afc458c5ddf1dfd16de58068af168f4d72 Mon Sep 17 00:00:00 2001
From: Michael McMahon
Date: Thu, 3 Mar 2011 17:14:23 +0000
Subject: [PATCH 48/59] 7024264: HttpURLConnection/NetPermission doc issue
Reviewed-by: chegar
---
jdk/src/share/classes/java/net/HttpURLConnection.java | 3 ++-
jdk/src/share/classes/java/net/NetPermission.java | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/jdk/src/share/classes/java/net/HttpURLConnection.java b/jdk/src/share/classes/java/net/HttpURLConnection.java
index db4fc05d905..3b74394f6cd 100644
--- a/jdk/src/share/classes/java/net/HttpURLConnection.java
+++ b/jdk/src/share/classes/java/net/HttpURLConnection.java
@@ -400,7 +400,8 @@ abstract public class HttpURLConnection extends URLConnection {
* @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 {
diff --git a/jdk/src/share/classes/java/net/NetPermission.java b/jdk/src/share/classes/java/net/NetPermission.java
index 0c459c3d5ab..2e1a2c93bba 100644
--- a/jdk/src/share/classes/java/net/NetPermission.java
+++ b/jdk/src/share/classes/java/net/NetPermission.java
@@ -73,6 +73,13 @@ import java.util.StringTokenizer;
*
*
*
+ *
getNetworkInformation
+ *
The ability to retrieve all information about local network interfaces.
+ *
Malicious code can read information about network hardware such as
+ * MAC addresses, which could be used to construct local IPv6 addresses.
+ *
+ *
+ *
*
getProxySelector
*
The ability to get the proxy selector used to make decisions
* on which proxies to use when making network connections.
From f13a584b8a2096382256fa882d686de7b1e752f2 Mon Sep 17 00:00:00 2001
From: Clemens Eisserer
Date: Thu, 3 Mar 2011 16:06:42 -0800
Subject: [PATCH 49/59] 7023589: Xrender : NullPointerException in
sun.font.XRGlyphCache.freeGlyphs running Java 2D demo
Reviewed-by: prr
---
.../share/classes/sun/font/StrikeCache.java | 10 +++---
.../classes/sun/font/XRGlyphCache.java | 35 ++++++++++---------
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/jdk/src/share/classes/sun/font/StrikeCache.java b/jdk/src/share/classes/sun/font/StrikeCache.java
index a7aa1f5846c..46c7b7a9a9e 100644
--- a/jdk/src/share/classes/sun/font/StrikeCache.java
+++ b/jdk/src/share/classes/sun/font/StrikeCache.java
@@ -319,8 +319,7 @@ public final class StrikeCache {
ArrayList gids = null;
for (int i = 0; i < glyphPtrs.length; i++) {
- if (glyphPtrs[i] != 0 && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0
- && unsafe.getInt(glyphPtrs[i] + cacheCellOffset) != 0) {
+ if (glyphPtrs[i] != 0 && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0) {
if (gids == null) {
gids = new ArrayList();
@@ -330,6 +329,8 @@ public final class StrikeCache {
}
if (gids != null) {
+ // Any reference by the disposers to the native glyph ptrs
+ // must be done before this returns.
notifyDisposeListeners(gids);
}
}
@@ -345,8 +346,7 @@ public final class StrikeCache {
for (int i=0; i < glyphPtrs.length; i++) {
if (glyphPtrs[i] != 0
- && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0
- && unsafe.getInt(glyphPtrs[i] + cacheCellOffset) != 0) {
+ && unsafe.getByte(glyphPtrs[i] + managedOffset) == 0) {
if (gids == null) {
gids = new ArrayList();
@@ -356,6 +356,8 @@ public final class StrikeCache {
}
if (gids != null) {
+ // Any reference by the disposers to the native glyph ptrs
+ // must be done before this returns.
notifyDisposeListeners(gids);
}
}
diff --git a/jdk/src/solaris/classes/sun/font/XRGlyphCache.java b/jdk/src/solaris/classes/sun/font/XRGlyphCache.java
index 9e767242b9f..7dbb23a774f 100644
--- a/jdk/src/solaris/classes/sun/font/XRGlyphCache.java
+++ b/jdk/src/solaris/classes/sun/font/XRGlyphCache.java
@@ -70,9 +70,14 @@ public class XRGlyphCache implements GlyphDisposedListener {
try {
SunToolkit.awtLock();
- ArrayList glyphIDList = new ArrayList(glyphPtrList.size());
+ GrowableIntArray glyphIDList = new GrowableIntArray(1, glyphPtrList.size());
for (long glyphPtr : glyphPtrList) {
- glyphIDList.add(XRGlyphCacheEntry.getGlyphID(glyphPtr));
+ int glyphID = XRGlyphCacheEntry.getGlyphID(glyphPtr);
+
+ //Check if glyph hasn't been freed already
+ if (glyphID != 0) {
+ glyphIDList.addInt(glyphID);
+ }
}
freeGlyphs(glyphIDList);
} finally {
@@ -83,7 +88,6 @@ public class XRGlyphCache implements GlyphDisposedListener {
protected int getFreeGlyphID() {
if (freeGlyphIDs.size() > 0) {
int newID = freeGlyphIDs.remove(freeGlyphIDs.size() - 1);
- ;
return newID;
}
return nextID++;
@@ -246,7 +250,7 @@ public class XRGlyphCache implements GlyphDisposedListener {
glyph.setPinned();
}
- ArrayList deleteGlyphList = new ArrayList();
+ GrowableIntArray deleteGlyphList = new GrowableIntArray(1, 10);
int pixelsToRelease = cachedPixels - MAX_CACHED_PIXELS;
for (int i = cacheList.size() - 1; i >= 0 && pixelsToRelease > 0; i--) {
@@ -254,7 +258,7 @@ public class XRGlyphCache implements GlyphDisposedListener {
if (!entry.isPinned()) {
pixelsToRelease -= entry.getPixelCnt();
- deleteGlyphList.add(new Integer(entry.getGlyphID()));
+ deleteGlyphList.addInt(entry.getGlyphID());
}
}
@@ -265,26 +269,23 @@ public class XRGlyphCache implements GlyphDisposedListener {
freeGlyphs(deleteGlyphList);
}
- private void freeGlyphs(List glyphIdList) {
+ private void freeGlyphs(GrowableIntArray glyphIdList) {
+ GrowableIntArray removedLCDGlyphs = new GrowableIntArray(1, 10);
+ GrowableIntArray removedGrayscaleGlyphs = new GrowableIntArray(1, 10);
- freeGlyphIDs.addAll(glyphIdList);
+ for (int i=0; i < glyphIdList.getSize(); i++) {
+ int glyphId = glyphIdList.getInt(i);
+ freeGlyphIDs.add(glyphId);
- GrowableIntArray removedLCDGlyphs = new GrowableIntArray(1, 1);
- GrowableIntArray removedGrayscaleGlyphs = new GrowableIntArray(1, 1);
-
- for (Integer glyphId : glyphIdList) {
- tmp.setValue(glyphId.intValue());
+ tmp.setValue(glyphId);
XRGlyphCacheEntry entry = cacheMap.get(tmp);
cachedPixels -= entry.getPixelCnt();
-
- int removedGlyphID = entry.getGlyphID();
- tmp.setValue(removedGlyphID);
cacheMap.remove(tmp);
if (entry.getGlyphSet() == grayGlyphSet) {
- removedGrayscaleGlyphs.addInt(removedGlyphID);
+ removedGrayscaleGlyphs.addInt(glyphId);
} else {
- removedLCDGlyphs.addInt(removedGlyphID);
+ removedLCDGlyphs.addInt(glyphId);
}
entry.setGlyphID(0);
From 1d820278f6f3fb18fcf16e33c82740c8aa592dc7 Mon Sep 17 00:00:00 2001
From: Alan Bateman
Date: Fri, 4 Mar 2011 09:29:56 +0000
Subject: [PATCH 50/59] 6944810: (ch) Assert failure in
sun.nio.ch.PendingIoCache.clearPendingIoMap [win]
Reviewed-by: chegar
---
.../nio/channels/AsynchronousFileChannel.java | 4 ++--
.../classes/sun/nio/ch/PendingIoCache.java | 7 ++++---
.../WindowsAsynchronousFileChannelImpl.java | 13 +++++++-----
.../WindowsAsynchronousSocketChannelImpl.java | 4 ++--
jdk/test/ProblemList.txt | 21 -------------------
5 files changed, 16 insertions(+), 33 deletions(-)
diff --git a/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java b/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java
index 4f4ac7f4a36..3e90769d329 100644
--- a/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java
+++ b/jdk/src/share/classes/java/nio/channels/AsynchronousFileChannel.java
@@ -48,7 +48,7 @@ import java.util.Collections;
*
*
An asynchronous file channel does not have a current position
* 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
@@ -73,7 +73,7 @@ import java.util.Collections;
* 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 identity).
* 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
diff --git a/jdk/src/windows/classes/sun/nio/ch/PendingIoCache.java b/jdk/src/windows/classes/sun/nio/ch/PendingIoCache.java
index 3d78a733c8c..7a4b1e3e319 100644
--- a/jdk/src/windows/classes/sun/nio/ch/PendingIoCache.java
+++ b/jdk/src/windows/classes/sun/nio/ch/PendingIoCache.java
@@ -110,8 +110,7 @@ class PendingIoCache {
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 @@ class PendingIoCache {
closePending = true;
try {
this.wait(50);
- } catch (InterruptedException x) { }
+ } catch (InterruptedException x) {
+ Thread.currentThread().interrupt();
+ }
closePending = false;
if (pendingIoMap.isEmpty())
return;
diff --git a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java
index 694b23a34a9..82405875928 100644
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousFileChannelImpl.java
@@ -439,6 +439,7 @@ public class WindowsAsynchronousFileChannelImpl
address = ((DirectBuffer)buf).address();
}
+ boolean pending = false;
try {
begin();
@@ -449,6 +450,7 @@ public class WindowsAsynchronousFileChannelImpl
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 @@ public class WindowsAsynchronousFileChannelImpl
// 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);
}
diff --git a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java
index 28d3c074549..2cc9cf026af 100644
--- a/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java
+++ b/jdk/src/windows/classes/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.java
@@ -239,14 +239,14 @@ class WindowsAsynchronousSocketChannelImpl
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));
}
diff --git a/jdk/test/ProblemList.txt b/jdk/test/ProblemList.txt
index 62c19030b00..27518785b07 100644
--- a/jdk/test/ProblemList.txt
+++ b/jdk/test/ProblemList.txt
@@ -380,30 +380,9 @@ java/io/File/MaxPathLength.java windows-all
# 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
From a5c5bb811d1d01d32b3641170ea3db917454b5ab Mon Sep 17 00:00:00 2001
From: Kumar Srinivasan
Date: Fri, 4 Mar 2011 09:32:20 -0800
Subject: [PATCH 51/59] 7023963: (misc) fix diamond anon instances in the jdk
Reviewed-by: alanb, mchung, mcimadamore, dholmes
---
.../classes/com/sun/java/util/jar/pack/PackageReader.java | 4 ++--
.../classes/com/sun/java/util/jar/pack/PackageWriter.java | 4 ++--
.../nio/zipfs/src/com/sun/nio/zipfs/ZipDirectoryStream.java | 4 ++--
.../share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java
index 41436e7b3b4..d676ee8e6fb 100644
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java
@@ -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 @@ class PackageReader extends BandStructure {
return -1;
}
- Comparator entryOutputOrder = new Comparator<>() {
+ Comparator entryOutputOrder = new Comparator() {
public int compare(Entry e0, Entry e1) {
int k0 = getOutputIndex(e0);
int k1 = getOutputIndex(e1);
diff --git a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java
index 8220e115663..f531fb7d999 100644
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java
@@ -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 @@ class PackageWriter extends BandStructure {
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() {
public int compare(Object o0, Object o1) {
Map.Entry e0 = (Map.Entry) o0;
Map.Entry e1 = (Map.Entry) o1;
diff --git a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipDirectoryStream.java b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipDirectoryStream.java
index 10f6bd477a9..543220fc63a 100644
--- a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipDirectoryStream.java
+++ b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipDirectoryStream.java
@@ -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 @@ public class ZipDirectoryStream implements DirectoryStream {
} catch (IOException e) {
throw new IllegalStateException(e);
}
- return new Iterator<>() {
+ return new Iterator() {
private Path next;
@Override
public boolean hasNext() {
diff --git a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java
index b03ba2929eb..1232a27ff1f 100644
--- a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java
+++ b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java
@@ -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 @@ public class ZipPath implements Path {
@Override
public Iterator iterator() {
- return new Iterator<>() {
+ return new Iterator() {
private int i = 0;
@Override
From 2b73fac982c5f0ff14d5444c9fa57351c2a7a104 Mon Sep 17 00:00:00 2001
From: Xueming Shen
Date: Fri, 4 Mar 2011 11:35:53 -0800
Subject: [PATCH 52/59] 7023244: (zipfs) langtools CompileTest fails on
read-only file system
Replaced checkAccess with Files.isWritable()
Reviewed-by: alanb
---
.../demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java
index 40afd8afb84..fc43fd87ccf 100644
--- a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java
+++ b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java
@@ -112,11 +112,8 @@ public class ZipFileSystem extends FileSystem {
}
// 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);
From d048451ca290076aff8bd9ff3ae96500b9e5a3c2 Mon Sep 17 00:00:00 2001
From: Alan Bateman
Date: Fri, 4 Mar 2011 21:26:50 +0000
Subject: [PATCH 53/59] 7023403: (ch) sun.nio.ch.SolarisEventPort.startPoll
failed with AssertionError
Reviewed-by: forax
---
.../ch/UnixAsynchronousSocketChannelImpl.java | 19 ++++++++++++-------
.../AsynchronousSocketChannel/Basic.java | 2 +-
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java
index 13e4ad36434..37caeeb9bce 100644
--- a/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java
+++ b/jdk/src/solaris/classes/sun/nio/ch/UnixAsynchronousSocketChannelImpl.java
@@ -137,7 +137,7 @@ class UnixAsynchronousSocketChannelImpl
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 @@ class UnixAsynchronousSocketChannelImpl
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,
@@ -402,9 +409,8 @@ class UnixAsynchronousSocketChannelImpl
exc = x;
} finally {
// restart poll in case of concurrent write
- synchronized (updateLock) {
- updateEvents();
- }
+ if (!(exc instanceof AsynchronousCloseException))
+ lockAndUpdateEvents();
end();
}
@@ -598,9 +604,8 @@ class UnixAsynchronousSocketChannelImpl
exc = x;
} finally {
// restart poll in case of concurrent write
- synchronized (updateLock) {
- updateEvents();
- }
+ if (!(exc instanceof AsynchronousCloseException))
+ lockAndUpdateEvents();
end();
}
diff --git a/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java b/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java
index 9f67fc37113..afe61d6d80a 100644
--- a/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java
+++ b/jdk/test/java/nio/channels/AsynchronousSocketChannel/Basic.java
@@ -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
*/
From fb59857e93b79fa263473894a3366c2a6d31ac4f Mon Sep 17 00:00:00 2001
From: Phil Race
Date: Fri, 4 Mar 2011 15:54:41 -0800
Subject: [PATCH 54/59] 7023591: Xrender: java2D font demo - text highlighting
tab content is black
Reviewed-by: flar
---
jdk/src/share/classes/sun/java2d/pipe/AAShapePipe.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jdk/src/share/classes/sun/java2d/pipe/AAShapePipe.java b/jdk/src/share/classes/sun/java2d/pipe/AAShapePipe.java
index 8654bede25c..4cba5a0b2a1 100644
--- a/jdk/src/share/classes/sun/java2d/pipe/AAShapePipe.java
+++ b/jdk/src/share/classes/sun/java2d/pipe/AAShapePipe.java
@@ -109,7 +109,7 @@ public class AAShapePipe
Region clip = sg.getCompClip();
int abox[] = new int[4];
AATileGenerator aatg =
- renderengine.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, 0, 0,
+ renderengine.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, lw1, lw2,
clip, abox);
if (aatg == null) {
// Nothing to render
From 1af9167ee76edceaa351ff64c5aacd0de36554e9 Mon Sep 17 00:00:00 2001
From: Pavel Porvatov
Date: Sat, 5 Mar 2011 18:27:51 +0300
Subject: [PATCH 55/59] 6760148: Certain fonts are not correctly soft wrapped
when using JTextComponent.print()
Reviewed-by: peterz
---
.../classes/javax/swing/text/Utilities.java | 31 +++++--------------
.../javax/swing/text/WrappedPlainView.java | 8 ++---
2 files changed, 11 insertions(+), 28 deletions(-)
diff --git a/jdk/src/share/classes/javax/swing/text/Utilities.java b/jdk/src/share/classes/javax/swing/text/Utilities.java
index 704cfa02c84..e3ef4940d5a 100644
--- a/jdk/src/share/classes/javax/swing/text/Utilities.java
+++ b/jdk/src/share/classes/javax/swing/text/Utilities.java
@@ -390,11 +390,15 @@ public class Utilities {
}
if ((x >= currX) && (x < nextX)) {
// found the hit position... return the appropriate side
- if ((round == false) || ((x - currX) < (nextX - x))) {
- return i - txtOffset;
- } else {
- return i + 1 - txtOffset;
+ int offset = ((round == false) || ((x - currX) < (nextX - x))) ?
+ (i - txtOffset) : (i + 1 - txtOffset);
+ // the length of the string measured as a whole may differ from
+ // the sum of individual character lengths, for example if
+ // fractional metrics are enabled; and we must guard from this.
+ while (metrics.charsWidth(txt, txtOffset, offset + 1) > (x - x0)) {
+ offset--;
}
+ return (offset < 0 ? 0 : offset);
}
currX = nextX;
}
@@ -403,24 +407,6 @@ public class Utilities {
return txtCount;
}
- /**
- * Adjust text offset so that the length of a resulting string as a whole
- * fits into the specified width.
- */
- static int adjustOffsetForFractionalMetrics(
- Segment s, FontMetrics fm, int offset, int width) {
- // Sometimes the offset returned by getTabbedTextOffset is beyond the
- // available area, when fractional metrics are enabled. We should
- // guard against this.
- if (offset < s.count) {
- while (offset > 0 &&
- fm.charsWidth(s.array, s.offset, offset + 1) > width) {
- offset--;
- }
- }
- return offset;
- }
-
/**
* Determine where to break the given text to fit
* within the given span. This tries to find a word boundary.
@@ -443,7 +429,6 @@ public class Utilities {
int txtCount = s.count;
int index = Utilities.getTabbedTextOffset(s, metrics, x0, x,
e, startOffset, false);
- index = adjustOffsetForFractionalMetrics(s, metrics, index, x - x0);
if (index >= txtCount - 1) {
return txtCount;
diff --git a/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java b/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java
index 2f02a7ca956..90d11659c2c 100644
--- a/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java
+++ b/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java
@@ -239,11 +239,9 @@ public class WrappedPlainView extends BoxView implements TabExpander {
tabBase, tabBase + currentWidth,
this, p0);
} else {
- int offset = Utilities.getTabbedTextOffset(segment, metrics,
- tabBase, tabBase + currentWidth, this, p0, false);
- offset = Utilities.adjustOffsetForFractionalMetrics(
- segment, metrics, offset, currentWidth);
- p = p0 + offset;
+ p = p0 + Utilities.getTabbedTextOffset(segment, metrics,
+ tabBase, tabBase + currentWidth,
+ this, p0, false);
}
SegmentCache.releaseSharedSegment(segment);
return p;
From 02b628a10f2ab2b602bb27862363be45b039897d Mon Sep 17 00:00:00 2001
From: Sean Coffey
Date: Mon, 7 Mar 2011 14:43:11 +0000
Subject: [PATCH 56/59] 7025105: TEST_BUG
test/com/sun/jndi/ldap/NoWaitForReplyTest.java should be cleaned up
Reviewed-by: alanb
---
.../com/sun/jndi/ldap/NoWaitForReplyTest.java | 127 ++++++++++--------
1 file changed, 70 insertions(+), 57 deletions(-)
diff --git a/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java b/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java
index 4a93ef41ff8..bb772c09bc5 100644
--- a/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java
+++ b/jdk/test/com/sun/jndi/ldap/NoWaitForReplyTest.java
@@ -38,81 +38,94 @@ public class NoWaitForReplyTest {
public static void main(String[] args) throws Exception {
- boolean passed = false;
-
- // Set up the environment for creating the initial context
- Hashtable env = new Hashtable(11);
- env.put(Context.PROVIDER_URL, "ldap://localhost:22001");
- 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");
-
- DummyServer ldapServer = new DummyServer();
-
- try {
+ boolean passed = false;
// start the LDAP server
+ DummyServer ldapServer = new DummyServer();
ldapServer.start();
- // Create initial context
- System.out.println("Client: connecting to the server");
- DirContext ctx = new InitialDirContext(env);
+ // 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");
- 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);
+ // Wait up to 10 seconds for a response from the LDAP server
+ env.put("com.sun.jndi.ldap.read.timeout", "10000");
- // 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");
+ // Don't wait until the first search reply is received
+ env.put("com.sun.jndi.ldap.search.waitForReply", "false");
- // Close the context when we're done
- ctx.close();
+ // Send the LDAP search request without first authenticating (no bind)
+ env.put("java.naming.ldap.version", "3");
- } 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");
+ 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 {
- static int serverPort = 22001;
+ private final ServerSocket serverSocket;
- DummyServer() {
- }
+ DummyServer() throws IOException {
+ this.serverSocket = new ServerSocket(0);
+ System.out.println("Server: listening on port " + serverSocket.getLocalPort());
+ }
- public void run() {
- try {
- ServerSocket serverSock = new ServerSocket(serverPort);
- Socket socket = serverSock.accept();
+ public int getPortNumber() {
+ return serverSocket.getLocalPort();
+ }
+
+ public void run() {
+ try (Socket socket = serverSocket.accept()) {
System.out.println("Server: accepted a connection");
- BufferedInputStream bin =
- new BufferedInputStream(socket.getInputStream());
+ InputStream in = socket.getInputStream();
- while (true) {
- bin.read();
+ while (!isInterrupted()) {
+ in.skip(in.available());
}
- } catch (IOException e) {
- // ignore
+
+ } catch (Exception e) {
+ // ignore
+
+ } finally {
+ System.out.println("Server: shutting down");
+ try {
+ serverSocket.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
}
}
}
-}
From 93b5e28256dac5075e01227d5ced210da5c21155 Mon Sep 17 00:00:00 2001
From: Sean Mullan
Date: Mon, 7 Mar 2011 13:20:55 -0500
Subject: [PATCH 57/59] 7022467: SecretKeyFactory doesn't support algorithm
"AES" on Windows and Linux
Reviewed-by: wetmore, valeriep
---
jdk/src/share/classes/javax/crypto/SecretKeyFactory.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/jdk/src/share/classes/javax/crypto/SecretKeyFactory.java b/jdk/src/share/classes/javax/crypto/SecretKeyFactory.java
index 1d00db7badb..bf32bae08c5 100644
--- a/jdk/src/share/classes/javax/crypto/SecretKeyFactory.java
+++ b/jdk/src/share/classes/javax/crypto/SecretKeyFactory.java
@@ -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 @@ import sun.security.jca.GetInstance.Instance;
*
Every implementation of the Java platform is required to support the
* following standard SecretKeyFactory algorithms:
*
- *
AES
*
DES
*
DESede
*
From 1daa47b01d4825eb89ba9c586db4cb93ef962d6b Mon Sep 17 00:00:00 2001
From: Valerie Peng
Date: Mon, 7 Mar 2011 14:14:37 -0800
Subject: [PATCH 58/59] 6994008: PKCS11 should support "RSA" and
"RSA/ECB/NoPadding" ciphers
Add support for RSA_X_509 mechanism and aliasing of "RSA" to "RSA/ECB/PKCS1Padding".
Reviewed-by: wetmore
---
.../sun/security/pkcs11/P11RSACipher.java | 19 +++-
.../sun/security/pkcs11/SunPKCS11.java | 4 +-
.../security/pkcs11/Cipher/TestRSACipher.java | 98 ++++++++++---------
.../pkcs11/Cipher/TestRSACipherWrap.java | 55 ++++++-----
.../pkcs11/Cipher/TestRawRSACipher.java | 84 ++++++++++++++++
5 files changed, 181 insertions(+), 79 deletions(-)
create mode 100644 jdk/test/sun/security/pkcs11/Cipher/TestRawRSACipher.java
diff --git a/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java b/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java
index 18f3ab450ef..d9dc4e77ef7 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/P11RSACipher.java
@@ -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 @@ final class P11RSACipher extends CipherSpi {
// 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 @@ final class P11RSACipher extends CipherSpi {
// 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 @@ final class P11RSACipher extends CipherSpi {
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 @@ final class P11RSACipher extends CipherSpi {
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) {
diff --git a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
index d1a1db3defd..d54c5617309 100644
--- a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
+++ b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
@@ -627,8 +627,10 @@ public final class SunPKCS11 extends AuthProvider {
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));
diff --git a/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java b/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java
index f1adba35d23..4f27ff5de0c 100644
--- a/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestRSACipher.java
@@ -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 @@ import javax.crypto.*;
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 @@ public class TestRSACipher extends PKCS11Test {
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);
-
- // invalid data
- c1.init(Cipher.DECRYPT_MODE, publicKey);
- try {
+ c1.init(Cipher.ENCRYPT_MODE, publicKey);
+ e = c1.doFinal(b);
+ c1.init(Cipher.DECRYPT_MODE, privateKey);
d = c1.doFinal(e);
- throw new Exception("completed call");
- } catch (BadPaddingException ee) {
- ee.printStackTrace();
- }
+ match(b, d);
+ c2.init(Cipher.DECRYPT_MODE, privateKey);
+ 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);
+ // invalid data
+ c1.init(Cipher.DECRYPT_MODE, publicKey);
+ try {
+ d = c1.doFinal(e);
+ throw new Exception("completed call");
+ } catch (BadPaddingException ee) {
+ ee.printStackTrace();
+ }
- // 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.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.update(new byte[256]);
- try {
+ // 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();
- 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 {
diff --git a/jdk/test/sun/security/pkcs11/Cipher/TestRSACipherWrap.java b/jdk/test/sun/security/pkcs11/Cipher/TestRSACipherWrap.java
index 159bb50a029..c00b39942cc 100644
--- a/jdk/test/sun/security/pkcs11/Cipher/TestRSACipherWrap.java
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestRSACipherWrap.java
@@ -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 @@ import javax.crypto.spec.SecretKeySpec;
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);
}
}
}
diff --git a/jdk/test/sun/security/pkcs11/Cipher/TestRawRSACipher.java b/jdk/test/sun/security/pkcs11/Cipher/TestRawRSACipher.java
new file mode 100644
index 00000000000..d1dd0206031
--- /dev/null
+++ b/jdk/test/sun/security/pkcs11/Cipher/TestRawRSACipher.java
@@ -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());
+ }
+}
From a36a5ce5999ad092e47a9bbdfa1534422bdc2362 Mon Sep 17 00:00:00 2001
From: Alan Bateman
Date: Tue, 8 Mar 2011 10:32:18 +0000
Subject: [PATCH 59/59] 7025468: Tests using diamond with anonymous inner
classes needs to be reverted
Reviewed-by: dholmes, forax
---
jdk/test/java/nio/file/DirectoryStream/Basic.java | 2 +-
jdk/test/java/util/PriorityQueue/NoNulls.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/jdk/test/java/nio/file/DirectoryStream/Basic.java b/jdk/test/java/nio/file/DirectoryStream/Basic.java
index 69f5d18f656..ec9d68ffd17 100644
--- a/jdk/test/java/nio/file/DirectoryStream/Basic.java
+++ b/jdk/test/java/nio/file/DirectoryStream/Basic.java
@@ -69,7 +69,7 @@ public class Basic {
throw new RuntimeException("entry not found");
// check filtering: f* should match foo
- DirectoryStream.Filter filter = new DirectoryStream.Filter<>() {
+ DirectoryStream.Filter filter = new DirectoryStream.Filter() {
private PathMatcher matcher =
dir.getFileSystem().getPathMatcher("glob:f*");
public boolean accept(Path file) {
diff --git a/jdk/test/java/util/PriorityQueue/NoNulls.java b/jdk/test/java/util/PriorityQueue/NoNulls.java
index a56259a8ae0..21f76876b4c 100644
--- a/jdk/test/java/util/PriorityQueue/NoNulls.java
+++ b/jdk/test/java/util/PriorityQueue/NoNulls.java
@@ -53,7 +53,7 @@ import java.util.concurrent.PriorityBlockingQueue;
public class NoNulls {
void test(String[] args) throws Throwable {
final Comparator nullTolerantComparator
- = new Comparator<>() {
+ = new Comparator() {
public int compare(String x, String y) {
return (x == null ? -1 :
y == null ? 1 :
@@ -65,7 +65,7 @@ public class NoNulls {
nullSortedSet.add(null);
final PriorityQueue nullPriorityQueue
- = new PriorityQueue<>() {
+ = new PriorityQueue() {
public Object[] toArray() { return new Object[] { null };}};
final Collection nullCollection = new ArrayList<>();