Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why does getCookies() return null?

 
Garrett Smith
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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).
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
James.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic