This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why does getCookies() return null? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why does getCookies() return null?" Watch "Why does getCookies() return null?" New topic

Why does getCookies() return null?

Garrett Smith
Ranch Hand

Joined: Jun 27, 2002
Posts: 401

The obvious negative implication of this poor approach is that it requires implementors to double check.

It is always a good idea to return a 0 length array instead of null when the method returns an Array type. I wonder why they did not change this in the new servlet spec. Why did they do this?

Note: I had to put an underscore before the cookie method in question to pass the ubb forum software. The real method has no underscore (you knew that).

comp.lang.javascript FAQ:
James Turner
Ranch Hand

Joined: May 10, 2004
Posts: 194
I think you are right about that...I think in most cases, when a data structure is expected, it should be an empty one rather then a null.

Also the inconsistency in the getUserPrinciple() in the servlet spec returns null when no principle is present, but in EJB it returns an empty principle object. (There is also a naming inconsistency, to top it all off, in EJB the same method is called getCallerPrincipal() ).

I don't think the spec architects collaborate that much.

Anyway, that just seems strange to me, uniformity is lacking in most specs.


James<br />SCJP 1.4 - 92%<br />SCJD - 93%<br />SCWCD 1.4 - 95%<br />SCBCD 1.3 - 100%<br />SCEA - 92%
I agree. Here's the link:
subject: Why does getCookies() return null?
jQuery in Action, 3rd edition