November 8th, 2006 (11:35 am)
current mood: shocked
Hey, we're all a bit arrogant when we're coding sometimes, but you've got to love the following comment I just found regarding String.split:
/**
* Convenience method to build a string array from a delimited string.
* Due to a silly bug in split, it will only return all empty tokens if there is at least
* one non-empty token at the end of the string. To get around this, a dummy token is added
* to the string before splitting. This dummy token is removed to the returned string array.
*
*/
Sigh - so there's this crazy bug in split() that no one else has ever noticed!! ;p
Unfortunately I can't work out who the original author is in order to educate them, so I've just checked it back in to CVS with the following amendment:
* -- As I can't be sure who wrote this, I'm writing this comment in the hope they'll
* see it:
* BTW, this isn't a "silly bug" in split - using the one arg method split calls
* split(String re, int limit) with a limit of 0. The API documentation clearly states:
* "If n is zero then the pattern will be applied as many times as possible, the array can
* have any length, and trailing empty strings will be discarded."
*
* What should actually be done is to use split(delimitedString, -1);
*
without actually amending the code (it would have to be regression tested, and the "workaround" does work I guess...).