< prev index next >

src/java.base/share/classes/java/net/CookieManager.java

Print this page

        

@@ -79,11 +79,11 @@
  *     to use it.
  *   </li>
  *   <li>
  *     Currently, only CookieStore.add(URI, HttpCookie) and CookieStore.get(URI)
  *     are used by CookieManager. Others are for completeness and might be needed
- *     by a more sophisticated CookieStore implementation, e.g. a NetscapeCookieSotre.
+ *     by a more sophisticated CookieStore implementation, e.g. a NetscapeCookieStore.
  *   </li>
  * </ul>
  * </blockquote>
  *
  * <p>There're various ways user can hook up his own HTTP cookie management behavior, e.g.

@@ -199,14 +199,13 @@
         // pre-condition check
         if (uri == null || requestHeaders == null) {
             throw new IllegalArgumentException("Argument is null");
         }
 
-        Map<String, List<String>> cookieMap = new java.util.HashMap<>();
         // if there's no default CookieStore, no way for us to get any cookie
         if (cookieJar == null)
-            return Collections.unmodifiableMap(cookieMap);
+            return Map.of();
 
         boolean secureLink = "https".equalsIgnoreCase(uri.getScheme());
         List<HttpCookie> cookies = new java.util.ArrayList<>();
         String path = uri.getPath();
         if (path == null || path.isEmpty()) {

@@ -242,12 +241,11 @@
         }
 
         // apply sort rule (RFC 2965 sec. 3.3.4)
         List<String> cookieHeader = sortByPath(cookies);
 
-        cookieMap.put("Cookie", cookieHeader);
-        return Collections.unmodifiableMap(cookieMap);
+        return Map.of("Cookie", cookieHeader);
     }
 
     public void
         put(URI uri, Map<String, List<String>> responseHeaders)
         throws IOException
< prev index next >