jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
changeset 10596 39b3a979e600
parent 10136 af9631156b25
child 10701 2c8dde454979
--- a/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Thu Sep 15 14:10:30 2011 +0100
+++ b/jdk/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Fri Sep 16 12:09:04 2011 -0700
@@ -25,6 +25,7 @@
 
 package sun.net.www.protocol.http;
 
+import java.util.Arrays;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.ProtocolException;
@@ -229,9 +230,9 @@
             bufSize4ES = 4096; // use the default
         }
 
-        allowRestrictedHeaders = ((Boolean)java.security.AccessController.doPrivileged(
+        allowRestrictedHeaders = java.security.AccessController.doPrivileged(
                 new sun.security.action.GetBooleanAction(
-                    "sun.net.http.allowRestrictedHeaders"))).booleanValue();
+                    "sun.net.http.allowRestrictedHeaders")).booleanValue();
         if (!allowRestrictedHeaders) {
             restrictedHeaderSet = new HashSet<String>(restrictedHeaders.length);
             for (int i=0; i < restrictedHeaders.length; i++) {
@@ -289,6 +290,7 @@
      * REMIND:  backwards compatibility with JDK 1.1.  Should be
      * eliminated for JDK 2.0.
      */
+    @Deprecated
     private static HttpAuthenticator defaultAuth;
 
     /* all the headers we send
@@ -750,6 +752,7 @@
     /**
      * @deprecated.  Use java.net.Authenticator.setDefault() instead.
      */
+    @Deprecated
     public static void setDefaultAuthenticator(HttpAuthenticator a) {
         defaultAuth = a;
     }
@@ -830,8 +833,7 @@
                     InetAddress a1 = InetAddress.getByName(h1);
                     InetAddress a2 = InetAddress.getByName(h2);
                     result[0] = a1.equals(a2);
-                } catch(UnknownHostException e) {
-                } catch(SecurityException e) {
+                } catch(UnknownHostException | SecurityException e) {
                 }
                 return null;
             }
@@ -1336,9 +1338,9 @@
 
                     // Read comments labeled "Failed Negotiate" for details.
                     boolean dontUseNegotiate = false;
-                    Iterator iter = responses.multiValueIterator("Proxy-Authenticate");
+                    Iterator<String> iter = responses.multiValueIterator("Proxy-Authenticate");
                     while (iter.hasNext()) {
-                        String value = ((String)iter.next()).trim();
+                        String value = iter.next().trim();
                         if (value.equalsIgnoreCase("Negotiate") ||
                                 value.equalsIgnoreCase("Kerberos")) {
                             if (!inNegotiateProxy) {
@@ -1414,9 +1416,9 @@
 
                     // Read comments labeled "Failed Negotiate" for details.
                     boolean dontUseNegotiate = false;
-                    Iterator iter = responses.multiValueIterator("WWW-Authenticate");
+                    Iterator<String> iter = responses.multiValueIterator("WWW-Authenticate");
                     while (iter.hasNext()) {
-                        String value = ((String)iter.next()).trim();
+                        String value = iter.next().trim();
                         if (value.equalsIgnoreCase("Negotiate") ||
                                 value.equalsIgnoreCase("Kerberos")) {
                             if (!inNegotiate) {
@@ -1585,9 +1587,8 @@
                                 // HttpsURLConnection instance saved in
                                 // DelegateHttpsURLConnection
                                 uconn = (URLConnection)this.getClass().getField("httpsURLConnection").get(this);
-                                } catch (IllegalAccessException iae) {
-                                    // ignored; use 'this'
-                                } catch (NoSuchFieldException nsfe) {
+                                } catch (IllegalAccessException |
+                                         NoSuchFieldException e) {
                                     // ignored; use 'this'
                                 }
                             }
@@ -1786,9 +1787,9 @@
                 if (respCode == HTTP_PROXY_AUTH) {
                     // Read comments labeled "Failed Negotiate" for details.
                     boolean dontUseNegotiate = false;
-                    Iterator iter = responses.multiValueIterator("Proxy-Authenticate");
+                    Iterator<String> iter = responses.multiValueIterator("Proxy-Authenticate");
                     while (iter.hasNext()) {
-                        String value = ((String)iter.next()).trim();
+                        String value = iter.next().trim();
                         if (value.equalsIgnoreCase("Negotiate") ||
                                 value.equalsIgnoreCase("Kerberos")) {
                             if (!inNegotiateProxy) {
@@ -1938,6 +1939,7 @@
      * Gets the authentication for an HTTP proxy, and applies it to
      * the connection.
      */
+    @SuppressWarnings("fallthrough")
     private AuthenticationInfo getHttpProxyAuthentication (AuthenticationHeader authhdr) {
         /* get authorization from authenticator */
         AuthenticationInfo ret = null;
@@ -2004,13 +2006,13 @@
                     }
                     break;
                 case NTLM:
-                    if (NTLMAuthenticationProxy.proxy.supported) {
+                    if (NTLMAuthenticationProxy.supported) {
                         /* tryTransparentNTLMProxy will always be true the first
                          * time around, but verify that the platform supports it
                          * otherwise don't try. */
                         if (tryTransparentNTLMProxy) {
                             tryTransparentNTLMProxy =
-                                    NTLMAuthenticationProxy.proxy.supportsTransparentAuth;
+                                    NTLMAuthenticationProxy.supportsTransparentAuth;
                         }
                         a = null;
                         if (tryTransparentNTLMProxy) {
@@ -2043,6 +2045,7 @@
                     break;
                 case UNKNOWN:
                     logger.finest("Unknown/Unsupported authentication scheme: " + scheme);
+                /*fall through*/
                 default:
                     throw new AssertionError("should not reach here");
                 }
@@ -2080,6 +2083,7 @@
      * @param authHdr the AuthenticationHeader which tells what auth scheme is
      * prefered.
      */
+    @SuppressWarnings("fallthrough")
     private AuthenticationInfo getServerAuthentication (AuthenticationHeader authhdr) {
         /* get authorization from authenticator */
         AuthenticationInfo ret = null;
@@ -2150,7 +2154,7 @@
                     }
                     break;
                 case NTLM:
-                    if (NTLMAuthenticationProxy.proxy.supported) {
+                    if (NTLMAuthenticationProxy.supported) {
                         URL url1;
                         try {
                             url1 = new URL (url, "/"); /* truncate the path */
@@ -2163,13 +2167,13 @@
                          * otherwise don't try. */
                         if (tryTransparentNTLMServer) {
                             tryTransparentNTLMServer =
-                                    NTLMAuthenticationProxy.proxy.supportsTransparentAuth;
+                                    NTLMAuthenticationProxy.supportsTransparentAuth;
                             /* If the platform supports transparent authentication
                              * then check if we are in a secure environment
                              * whether, or not, we should try transparent authentication.*/
                             if (tryTransparentNTLMServer) {
                                 tryTransparentNTLMServer =
-                                        NTLMAuthenticationProxy.proxy.isTrustedSite(url);
+                                        NTLMAuthenticationProxy.isTrustedSite(url);
                             }
                         }
                         a = null;
@@ -2198,6 +2202,7 @@
                     break;
                 case UNKNOWN:
                     logger.finest("Unknown/Unsupported authentication scheme: " + scheme);
+                /*fall through*/
                 default:
                     throw new AssertionError("should not reach here");
                 }
@@ -2745,14 +2750,14 @@
          * The cookies in the requests message headers may have
          * been modified. Use the saved user cookies instead.
          */
-        Map userCookiesMap = null;
+        Map<String, List<String>> userCookiesMap = null;
         if (userCookies != null || userCookies2 != null) {
-            userCookiesMap = new HashMap();
+            userCookiesMap = new HashMap<>();
             if (userCookies != null) {
-                userCookiesMap.put("Cookie", userCookies);
+                userCookiesMap.put("Cookie", Arrays.asList(userCookies));
             }
             if (userCookies2 != null) {
-                userCookiesMap.put("Cookie2", userCookies2);
+                userCookiesMap.put("Cookie2", Arrays.asList(userCookies2));
             }
         }
         return requests.filterAndAddHeaders(EXCLUDE_HEADERS2, userCookiesMap);