In the next line of code
Cookie cookie = request.getCookie();
The request.getCookie() method passes refrence to the Cookie .
If you change the cookie by later cookie by doing something like
cookie = foo_bar(); /* (2) */
Then you change the internal refrence. This in no way affects your original Cookie in (1)
If you changed the Cookie by doing something like
cookie.setFoo( bar );
Then you change the original object obtained in (1)
source share