Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8365086

CookieStore.getURIs() and get(URI) should return an immutable List

XMLWordPrintable

    • master
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      CookieStore.getURIs should return "an immutable list of URIs; return empty list if no cookie in this cookie store is associated with an URI" based on its JavaDoc, but actually it just returns an ArrayList, and can do some changes on this list.


      ---------- BEGIN SOURCE ----------
      import java.net.*;
      import java.util.*;

      public class ImmutableTest {
          public static void main(String[] args) throws Exception {
              CookieManager cm = new CookieManager();
              CookieStore cs = cm.getCookieStore();
              cs.add(new URI("https://immutable.example.com"), new HttpCookie("c", "v"));

              List<URI> uris = cs.getURIs();
              System.out.println(uris.getClass());
              System.out.println(uris);
              try {
                  uris.add(new URI("https://should.fail.example.com"));
                  System.out.println(uris);
                  throw new RuntimeException("immutable CookieStore URIs list should not allow modification");
              } catch (UnsupportedOperationException expected) {
                  // Test passed - expected exception
              }
          }
      }

      ---------- END SOURCE ----------

            jpai Jaikiran Pai
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: