- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
emptry string is null? is there i_hate_oracle club somewhere guys...
Admin
The real WTF is that you're all having a debate over the necessity of testing NULL and empty when the thing that's wrong with the code of the guy is simply that these tests have absolutely no use. It's like writing : if (isDead(grandma)) stompToDeath(grandma); Just to be sure huh?
Admin
You've probably never written code in PHP, where things like "empty" (eg. null) actually mean no-value or, at least, not equal to zero. cough
Similar issues happen for trying to find NULL values in MySQL, though they're a little more sensible (IMO).
Admin
Admin
A zero-length string literal is never null.
Admin
Actually, assuming you don't use the String constructor like a good little developer, == will work just fine with String. If two strings are equal, they should reference the same object in the string pool.
Of course then all it takes is one developer to use your method with a String that was create via myString = new String("") and everything breaks.
Admin
Unless you also want it to evaluate to true when the String is null (which would be the case here if what they meant to say is:
Admin
On the second code snippet:
Could this have been caused by a code-merge of a version control system (e.g. merging a branch back into trunk for whatever reason) ? I mean, I haven't actually had something like that happening to me before .... but AFAIK it is not out of the realm of the possible.
Admin
Admin
Admin
I hate oracle club.... http://forums.worsethanfailure.com/forums/17/ShowForum.aspx
wouldn't it be easier to learn how NULL works? Not how you want it to work.
Admin
Well, as far as i know it does not include any strings set at run-time which are usually those most in need of checking. On a slightly different note, I recall seeing this attempt of testing for empty strings in java/jsp:
String str = getParameter("paramId"); if( str.equals(null) || str.equals("") ){ str = //remainder omitted }
As you might guess, the null check is there in case the parameter is not sent at all by the posting jsp page while the empty string part is for testing if the user simply did not fill in the field in question. Needless to say, the person who wrote this beauty never actually bothered to test how his servlet handled a null posting of the parameter...
Admin
Unfornately there arent any real programmers here.
String.equals is always really bad because String can be null and it would throw a null pointer exception. So String.equals("") is just plain bad programming. A real programmer uses "".equals(String). Since "" is always a string an not null, no null pointer exception is ever thrown.