Here is my class, where i am concatenating two string.
String concatenate with null
using + operator execute smoothly but throws NullPointerException
If you see in java.lang.String source, and use null as parameter. NPE is thrown in first line in length() method.
public String concat(String str) {
int otherLen = str.length();//This is where NullPointerException is thrown
if (otherLen == 0) {
return this;
}
getChars(0, count, buf, 0);
str.getChars(0, otherLen, buf, count);
return new String(0, count + otherLen, buf);
}