Merge
authoramurillo
Tue, 14 Jun 2016 20:17:41 -0700
changeset 38960 87f36eb83b2e
parent 38959 e4dec0a22af2 (current diff)
parent 38955 1dc95586a112 (diff)
child 38961 c350f63c6b34
Merge
--- a/jdk/src/java.base/share/classes/java/time/chrono/JapaneseDate.java	Tue Jun 14 10:22:07 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/time/chrono/JapaneseDate.java	Tue Jun 14 20:17:41 2016 -0700
@@ -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 @@
                 field == ALIGNED_WEEK_OF_MONTH || field == ALIGNED_WEEK_OF_YEAR) {
             return false;
         }
-        return ChronoLocalDate.super.isSupported(field);
+        return super.isSupported(field);
     }
 
     @Override
--- a/jdk/src/java.base/share/classes/java/util/Scanner.java	Tue Jun 14 10:22:07 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/util/Scanner.java	Tue Jun 14 20:17:41 2016 -0700
@@ -793,7 +793,6 @@
     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 @@
             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 @@
         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 @@
      */
     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 @@
             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 @@
         saveState();
         modCount++;
         while (!sourceClosed) {
-            if (hasTokenInBuffer())
+            if (hasTokenInBuffer()) {
                 return revertState(true);
+            }
             readInput();
         }
         boolean result = hasTokenInBuffer();
@@ -1365,7 +1369,6 @@
         ensureOpen();
         clearCaches();
         modCount++;
-
         while (true) {
             String token = getCompleteTokenInBuffer(null);
             if (token != null) {
--- a/jdk/src/java.base/share/classes/javax/security/auth/Policy.java	Tue Jun 14 10:22:07 2016 -0700
+++ b/jdk/src/java.base/share/classes/javax/security/auth/Policy.java	Tue Jun 14 20:17:41 2016 -0700
@@ -152,10 +152,11 @@
  *
  * 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;
--- a/jdk/test/java/util/Scanner/ScanTest.java	Tue Jun 14 10:22:07 2016 -0700
+++ b/jdk/test/java/util/Scanner/ScanTest.java	Tue Jun 14 20:17:41 2016 -0700
@@ -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 @@
             ioExceptionTest();
             matchTest();
             delimiterTest();
+            boundaryDelimTest();
             useLocaleTest();
             closeTest();
             cacheTest();
@@ -504,6 +505,54 @@
         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
--- a/jdk/test/javax/net/ssl/SSLSession/SessionCacheSizeTests.java	Tue Jun 14 10:22:07 2016 -0700
+++ b/jdk/test/javax/net/ssl/SSLSession/SessionCacheSizeTests.java	Tue Jun 14 20:17:41 2016 -0700
@@ -106,17 +106,21 @@
      */
     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 @@
         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 @@
             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 @@
         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 @@
                 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 @@
         // 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 @@
             serverThread.start();
         } else {
             try {
-                doServerSide(port, nConns);
+                doServerSide(nConns);
             } catch (Exception e) {
                 serverException = e;
             } finally {