From aa221e3a63f3b1a7465cc5c09c2ec0094946db36 Mon Sep 17 00:00:00 2001 From: Artem Smotrakov Date: Tue, 14 Jun 2016 10:27:23 -0700 Subject: [PATCH 1/4] 8159038: javax/net/ssl/SSLSession/SessionCacheSizeTests.java failed with java.net.SocketException: Address already in use Reviewed-by: xuelei --- .../ssl/SSLSession/SessionCacheSizeTests.java | 139 ++++++++++-------- 1 file changed, 78 insertions(+), 61 deletions(-) diff --git a/jdk/test/javax/net/ssl/SSLSession/SessionCacheSizeTests.java b/jdk/test/javax/net/ssl/SSLSession/SessionCacheSizeTests.java index cc5dd671fea..bb61abb35d5 100644 --- a/jdk/test/javax/net/ssl/SSLSession/SessionCacheSizeTests.java +++ b/jdk/test/javax/net/ssl/SSLSession/SessionCacheSizeTests.java @@ -106,17 +106,21 @@ public class SessionCacheSizeTests { */ static int MAX_ACTIVE_CONNECTIONS = 4; - void doServerSide(int serverPort, int serverConns) throws Exception { + static final int FREE_PORT = 0; + void doServerSide(int serverConns) throws Exception { try (SSLServerSocket sslServerSocket = - (SSLServerSocket) sslssf.createServerSocket(serverPort)) { + (SSLServerSocket) sslssf.createServerSocket(FREE_PORT)) { // timeout to accept a connection sslServerSocket.setSoTimeout(45000); // make sure createdPorts++ is atomic synchronized(serverPorts) { - serverPorts[createdPorts++] = sslServerSocket.getLocalPort(); + int serverPort = sslServerSocket.getLocalPort(); + System.out.printf("server #%d started on port %d%n", + createdPorts, serverPort); + serverPorts[createdPorts++] = serverPort; /* * Signal Client, we're ready for his connect. @@ -173,11 +177,54 @@ public class SessionCacheSizeTests { SSLSessionContext sessCtx = sslctx.getClientSessionContext(); sessCtx.setSessionTimeout(0); // no limit - while (nConnections < (MAX_ACTIVE_CONNECTIONS - 1)) { - // divide the connections among the available server ports + try { + while (nConnections < (MAX_ACTIVE_CONNECTIONS - 1)) { + // divide the connections among the available server ports + int serverPort = serverPorts [nConnections % (serverPorts.length)]; + System.out.printf("client #%d connects to port %d%n", + nConnections, serverPort); + sslSockets[nConnections] = (SSLSocket) sslsf. + createSocket("localhost", + serverPort); + InputStream sslIS = sslSockets[nConnections].getInputStream(); + OutputStream sslOS = sslSockets[nConnections].getOutputStream(); + sslOS.write(237); + sslOS.flush(); + int read = sslIS.read(); + SSLSession sess = sslSockets[nConnections].getSession(); + if (!sessions.contains(sess)) + sessions.add(sess); + nConnections++; + } + System.out.println("Current cacheSize is set to: " + + sessCtx.getSessionCacheSize()); + System.out.println(); + System.out.println("Currently cached Sessions......"); + System.out.println("============================================" + + "============================"); + System.out.println("Session " + + " Session-last-accessTime"); + System.out.println("============================================" + + "============================"); + checkCachedSessions(sessCtx, nConnections); + // Change session cache size + sessCtx.setSessionCacheSize(2); + System.out.println("Session cache size changed to: " + + sessCtx.getSessionCacheSize()); + System.out.println(); + checkCachedSessions(sessCtx, nConnections); + + // Test the effect of increasing the cache size + sessCtx.setSessionCacheSize(3); + System.out.println("Session cache size changed to: " + + sessCtx.getSessionCacheSize()); + // create a new session + int serverPort = serverPorts [nConnections % (serverPorts.length)]; + System.out.printf("client #%d connects to port %d%n", + nConnections, serverPort); sslSockets[nConnections] = (SSLSocket) sslsf. - createSocket("localhost", - serverPorts [nConnections % (serverPorts.length)]); + createSocket("localhost", + serverPort); InputStream sslIS = sslSockets[nConnections].getInputStream(); OutputStream sslOS = sslSockets[nConnections].getOutputStream(); sslOS.write(237); @@ -187,48 +234,15 @@ public class SessionCacheSizeTests { if (!sessions.contains(sess)) sessions.add(sess); nConnections++; - } - System.out.println("Current cacheSize is set to: " + - sessCtx.getSessionCacheSize()); - System.out.println(); - System.out.println("Currently cached Sessions......"); - System.out.println("============================================" - + "============================"); - System.out.println("Session " - + " Session-last-accessTime"); - System.out.println("============================================" - + "============================"); - checkCachedSessions(sessCtx, nConnections); - // Change session cache size - sessCtx.setSessionCacheSize(2); - System.out.println("Session cache size changed to: " - + sessCtx.getSessionCacheSize()); - System.out.println(); - checkCachedSessions(sessCtx, nConnections); - // Test the effect of increasing the cache size - sessCtx.setSessionCacheSize(3); - System.out.println("Session cache size changed to: " - + sessCtx.getSessionCacheSize()); - // create a new session - sslSockets[nConnections] = (SSLSocket) sslsf. - createSocket("localhost", - serverPorts [nConnections % (serverPorts.length)]); - InputStream sslIS = sslSockets[nConnections].getInputStream(); - OutputStream sslOS = sslSockets[nConnections].getOutputStream(); - sslOS.write(237); - sslOS.flush(); - int read = sslIS.read(); - SSLSession sess = sslSockets[nConnections].getSession(); - if (!sessions.contains(sess)) - sessions.add(sess); - nConnections++; - - // test the number of sessions cached against the cache size - checkCachedSessions(sessCtx, nConnections); - - for (int i = 0; i < nConnections; i++) { - sslSockets[i].close(); + // test the number of sessions cached against the cache size + checkCachedSessions(sessCtx, nConnections); + } finally { + for (int i = 0; i < nConnections; i++) { + if (sslSockets[i] != null) { + sslSockets[i].close(); + } + } } System.out.println("Session cache size tests passed"); } @@ -302,7 +316,9 @@ public class SessionCacheSizeTests { sslctx = SSLContext.getInstance("TLS"); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(new FileInputStream(keyFilename), passwd.toCharArray()); + try (FileInputStream fis = new FileInputStream(keyFilename)) { + ks.load(fis, passwd.toCharArray()); + } kmf.init(ks, passwd.toCharArray()); sslctx.init(kmf.getKeyManagers(), null, null); sslssf = (SSLServerSocketFactory) sslctx.getServerSocketFactory(); @@ -343,19 +359,21 @@ public class SessionCacheSizeTests { for (int i = 0; i < serverPorts.length; i++) { // distribute remaining connections among the // available ports - if (i < remainingConns) - startServer(serverPorts[i], (serverConns + 1), true); - else - startServer(serverPorts[i], serverConns, true); + if (i < remainingConns) { + startServer(serverConns + 1, true); + } else { + startServer(serverConns, true); + } } startClient(false); } else { startClient(true); for (int i = 0; i < serverPorts.length; i++) { - if (i < remainingConns) - startServer(serverPorts[i], (serverConns + 1), false); - else - startServer(serverPorts[i], serverConns, false); + if (i < remainingConns) { + startServer(serverConns + 1, false); + } else { + startServer(serverConns, false); + } } } } catch (Exception e) { @@ -420,13 +438,12 @@ public class SessionCacheSizeTests { // Fall-through: no exception to throw! } - void startServer(final int port, final int nConns, - boolean newThread) throws Exception { + void startServer(final int nConns, boolean newThread) throws Exception { if (newThread) { serverThread = new Thread() { public void run() { try { - doServerSide(port, nConns); + doServerSide(nConns); } catch (Exception e) { /* * Our server thread just died. @@ -443,7 +460,7 @@ public class SessionCacheSizeTests { serverThread.start(); } else { try { - doServerSide(port, nConns); + doServerSide(nConns); } catch (Exception e) { serverException = e; } finally { From 5aad7937b7fd3715b173ab1b0f7d093c1735dfc9 Mon Sep 17 00:00:00 2001 From: Xueming Shen Date: Tue, 14 Jun 2016 16:56:27 -0700 Subject: [PATCH 2/4] 8139414: java.util.Scanner hasNext() returns true, next() throws NoSuchElementException 8072582: Scanner delimits incorrectly when delimiter spans a buffer boundary Reviewed-by: smarks --- .../share/classes/java/util/Scanner.java | 39 +++++++------- jdk/test/java/util/Scanner/ScanTest.java | 51 ++++++++++++++++++- 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/util/Scanner.java b/jdk/src/java.base/share/classes/java/util/Scanner.java index a0e6dd89acc..32427e12801 100644 --- a/jdk/src/java.base/share/classes/java/util/Scanner.java +++ b/jdk/src/java.base/share/classes/java/util/Scanner.java @@ -793,7 +793,6 @@ public final class Scanner implements Iterator, Closeable { private void readInput() { if (buf.limit() == buf.capacity()) makeSpace(); - // Prepare to receive data int p = buf.position(); buf.position(buf.limit()); @@ -806,15 +805,12 @@ public final class Scanner implements Iterator, Closeable { lastException = ioe; n = -1; } - if (n == -1) { sourceClosed = true; needInput = false; } - if (n > 0) needInput = false; - // Restore current position and limit for reading buf.limit(buf.position()); buf.position(p); @@ -871,15 +867,20 @@ public final class Scanner implements Iterator, Closeable { matchValid = false; matcher.usePattern(delimPattern); matcher.region(position, buf.limit()); - // Skip delims first - if (matcher.lookingAt()) + if (matcher.lookingAt()) { + if (matcher.hitEnd() && !sourceClosed) { + // more input might change the match of delims, in which + // might change whether or not if there is token left in + // buffer (don't update the "position" in this case) + needInput = true; + return false; + } position = matcher.end(); - + } // If we are sitting at the end, no more tokens in buffer if (position == buf.limit()) return false; - return true; } @@ -900,7 +901,6 @@ public final class Scanner implements Iterator, Closeable { */ private String getCompleteTokenInBuffer(Pattern pattern) { matchValid = false; - // Skip delims first matcher.usePattern(delimPattern); if (!skipped) { // Enforcing only one skip of leading delims @@ -941,13 +941,16 @@ public final class Scanner implements Iterator, Closeable { foundNextDelim = matcher.find(); } if (foundNextDelim) { - // In the rare case that more input could cause the match - // to be lost and there is more input coming we must wait - // for more input. Note that hitting the end is okay as long - // as the match cannot go away. It is the beginning of the - // next delims we want to be sure about, we don't care if - // they potentially extend further. - if (matcher.requireEnd() && !sourceClosed) { + // In two rare cases that more input might cause the match to be + // lost or change. + // (1) if requireEnd() is true, more input might cause the match + // to be lost, we must wait for more input. + // (2) while hitting the end is okay IF the match does not + // go away AND the beginning of the next delims does not change + // (we don't care if they potentially extend further). But it's + // possible that more input could cause the beginning of the + // delims change, so have to wait for more input as well. + if ((matcher.requireEnd() || matcher.hitEnd()) && !sourceClosed) { needInput = true; return null; } @@ -1341,8 +1344,9 @@ public final class Scanner implements Iterator, Closeable { saveState(); modCount++; while (!sourceClosed) { - if (hasTokenInBuffer()) + if (hasTokenInBuffer()) { return revertState(true); + } readInput(); } boolean result = hasTokenInBuffer(); @@ -1365,7 +1369,6 @@ public final class Scanner implements Iterator, Closeable { ensureOpen(); clearCaches(); modCount++; - while (true) { String token = getCompleteTokenInBuffer(null); if (token != null) { diff --git a/jdk/test/java/util/Scanner/ScanTest.java b/jdk/test/java/util/Scanner/ScanTest.java index 45383f0674a..cc8bca9deaa 100644 --- a/jdk/test/java/util/Scanner/ScanTest.java +++ b/jdk/test/java/util/Scanner/ScanTest.java @@ -24,7 +24,7 @@ /** * @test * @bug 4313885 4926319 4927634 5032610 5032622 5049968 5059533 6223711 6277261 6269946 6288823 - * 8072722 + * 8072722 8072582 8139414 * @summary Basic tests of java.util.Scanner methods * @key randomness * @modules jdk.localedata @@ -70,6 +70,7 @@ public class ScanTest { ioExceptionTest(); matchTest(); delimiterTest(); + boundaryDelimTest(); useLocaleTest(); closeTest(); cacheTest(); @@ -504,6 +505,54 @@ public class ScanTest { report("Single delim test"); } + private static void append(StringBuilder sb, char c, int n) { + for (int i = 0; i < n; i++) { + sb.append(c); + } + } + + public static void boundaryDelimTest() throws Exception { + // 8072582 + StringBuilder sb = new StringBuilder(); + append(sb, 'a', 228); sb.append(","); + append(sb, 'b', 293); sb.append("#,#"); + append(sb, 'c', 308); sb.append(","); + append(sb, 'd', 188); sb.append("#,#"); + append(sb, 'e', 2); + try (Scanner scanner = new Scanner(sb.toString())) { + scanner.useDelimiter("(#,#)|(,)"); + while(scanner.hasNext()){ + String next = scanner.next(); + if(next.contains("#")){ + System.out.printf("[%s]%n", next); + failCount++; + } + } + } + + // 8139414 + int i = 1019; + sb = new StringBuilder(); + sb.append("--;"); + for (int j = 0; j < 1019; ++j) { + sb.append(j%10); + } + sb.append("-;-"); + String text = sb.toString(); + try (Scanner scanner = new Scanner(text)) { + scanner.useDelimiter("-;(-)?"); + while (scanner.hasNext()) { + scanner.next(); + } + } catch (NoSuchElementException e) { + System.out.println("Caught NoSuchElementException " + e); + e.printStackTrace(); + failCount++; + } + + report("delim at boundary test"); + } + /* * The hasNextPattern caches a match of a pattern called the regular cache * The hasNextType caches a match of that type called the type cache From ec6f5c4bf705e7bddad132f4edd51ac5dc81f490 Mon Sep 17 00:00:00 2001 From: Vicente Romero Date: Tue, 14 Jun 2016 18:19:54 -0700 Subject: [PATCH 3/4] 8159530: recent compiler change results in compile error in JapaneseDate.java Reviewed-by: darcy --- .../share/classes/java/time/chrono/JapaneseDate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jdk/src/java.base/share/classes/java/time/chrono/JapaneseDate.java b/jdk/src/java.base/share/classes/java/time/chrono/JapaneseDate.java index 0c1a876eae2..ccf3dcc3144 100644 --- a/jdk/src/java.base/share/classes/java/time/chrono/JapaneseDate.java +++ b/jdk/src/java.base/share/classes/java/time/chrono/JapaneseDate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, 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 @@ -437,7 +437,7 @@ public final class JapaneseDate field == ALIGNED_WEEK_OF_MONTH || field == ALIGNED_WEEK_OF_YEAR) { return false; } - return ChronoLocalDate.super.isSupported(field); + return super.isSupported(field); } @Override From 5d498d96f8c64dd5ce553de8be31b8f713eb8d4f Mon Sep 17 00:00:00 2001 From: Weijun Wang Date: Wed, 15 Jun 2016 10:13:21 +0800 Subject: [PATCH 4/4] 8157848: Mark deprecated javax.security.auth.Policy API with forRemoval=true Reviewed-by: mullan, xuelei --- .../java.base/share/classes/javax/security/auth/Policy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jdk/src/java.base/share/classes/javax/security/auth/Policy.java b/jdk/src/java.base/share/classes/javax/security/auth/Policy.java index 30db6987c9e..7180025c043 100644 --- a/jdk/src/java.base/share/classes/javax/security/auth/Policy.java +++ b/jdk/src/java.base/share/classes/javax/security/auth/Policy.java @@ -152,10 +152,11 @@ import sun.security.util.Debug; * * These two APIs provide callers the means to query the * Policy for Principal-based Permission entries. + * This class is subject to removal in a future version of Java SE. * * @see java.security.Security security properties */ -@Deprecated +@Deprecated(since="1.4", forRemoval=true) public abstract class Policy { private static Policy policy;