string stringbuffer append NULL strings
Posted on 2005-04-08
String dude = req.getParameter("dude") + "".trim();
String dudelen = dude.length();
This code at one time would return an empty string , I am certain with a length of 0(empty string).
Some strange behavior is now occurring.
dudelen is returning len of 4 because of the following:
x = "a" + 4 + "c"
x = new StringBuffer().append("a").append(4).append("c")
append: The characters of the String argument are appended, in order, to the contents of this string buffer, increasing the length of this string buffer by the length of the argument. If str is null, then the four characters "null" are appended to this string buffer.
I AM POSITIVE THIS WAS NOT ALWAYS THE CASE. Anyone know why this occurred?