A DESCRIPTION OF THE PROBLEM :
The JavaDoc for CookieStore.add(URI uri, HttpCookie cookie) contains misleading information that doesn't match the actual implementation behavior. Specifically, the documentation states: "If it is associated with an URI and its domain and path attribute are not specified, given URI will indicate where this cookie comes from." This statement strongly implies that the cookie's domain and path attributes will be automatically set based on the URI, but the actual implementation does not modify the HttpCookie object's properties.
Suggest Fix: Update Doc
/**
* Adds one HTTP cookie to the store. This is typically called for every incoming HTTP response.
*
* A cookie to store may or may not be associated with a URI. When associated with a URI, the
* CookieStore internally records this association without modifying the cookie object itself.
* This association is used to determine which cookies should be sent to which URIs in future requests.
*
* Important notes:
* - If a cookie's domain and path attributes are not specified, they will NOT be automatically
* set from the associated URI. To set these attributes, explicitly set them before calling add().
* - The URI association is only used for the CookieStore's internal matching logic and does not
* alter any properties of the cookie object.
*
* If a cookie with the same name corresponding to the given URI already exists in the store,
* it will be replaced with the new one.
*
* @param uri the URI to associate this cookie with. If null, this cookie will not be associated with any URI
* @param cookie the cookie to store
* @throws NullPointerException if the cookie parameter is null
* @see #get(java.net.URI)
*/
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Based on the current documentation, we would expect the cookie's domain and path attributes to be automatically set based on the associated URI when they were not specified.
ACTUAL -
The cookie's domain and path attributes remain null after being added to the CookieStore with a URI. The CookieStore only maintains an internal association between the cookie and the URI without modifying the cookie object itself.
---------- BEGIN SOURCE ----------
CookieManager cm = new CookieManager();
CookieStore cs = cm.getCookieStore();
HttpCookie cookie = new HttpCookie("COOKIE1", "COOKIE1");
URI uri = new URI("http://www.example.com/path");
cs.add(uri, cookie);
// The following assertion fails
assert "www.example.com".equals(cookie.getDomain());
// The following assertion fails
assert "/path".equals(cookie.getPath());
---------- END SOURCE ----------
The JavaDoc for CookieStore.add(URI uri, HttpCookie cookie) contains misleading information that doesn't match the actual implementation behavior. Specifically, the documentation states: "If it is associated with an URI and its domain and path attribute are not specified, given URI will indicate where this cookie comes from." This statement strongly implies that the cookie's domain and path attributes will be automatically set based on the URI, but the actual implementation does not modify the HttpCookie object's properties.
Suggest Fix: Update Doc
/**
* Adds one HTTP cookie to the store. This is typically called for every incoming HTTP response.
*
* A cookie to store may or may not be associated with a URI. When associated with a URI, the
* CookieStore internally records this association without modifying the cookie object itself.
* This association is used to determine which cookies should be sent to which URIs in future requests.
*
* Important notes:
* - If a cookie's domain and path attributes are not specified, they will NOT be automatically
* set from the associated URI. To set these attributes, explicitly set them before calling add().
* - The URI association is only used for the CookieStore's internal matching logic and does not
* alter any properties of the cookie object.
*
* If a cookie with the same name corresponding to the given URI already exists in the store,
* it will be replaced with the new one.
*
* @param uri the URI to associate this cookie with. If null, this cookie will not be associated with any URI
* @param cookie the cookie to store
* @throws NullPointerException if the cookie parameter is null
* @see #get(java.net.URI)
*/
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Based on the current documentation, we would expect the cookie's domain and path attributes to be automatically set based on the associated URI when they were not specified.
ACTUAL -
The cookie's domain and path attributes remain null after being added to the CookieStore with a URI. The CookieStore only maintains an internal association between the cookie and the URI without modifying the cookie object itself.
---------- BEGIN SOURCE ----------
CookieManager cm = new CookieManager();
CookieStore cs = cm.getCookieStore();
HttpCookie cookie = new HttpCookie("COOKIE1", "COOKIE1");
URI uri = new URI("http://www.example.com/path");
cs.add(uri, cookie);
// The following assertion fails
assert "www.example.com".equals(cookie.getDomain());
// The following assertion fails
assert "/path".equals(cookie.getPath());
---------- END SOURCE ----------