According to the Javadoc, HttpServletRequest.getCookies()
"Returns an array containing all of the Cookie objects the client sent with this request.", and it returns null
if no cookies were sent.
Is there a specific reason for this behavior other than returning an empty array, which seems a little more intuitive to me and avoids needing to check for null before iterating on the array to look for a specific cookie?
That used to be a common Java practice in situations like this. The main reason was probably due to it being slightly more efficient to return nothing than return an empty list (less work on the garbage collector).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With