I met a quite strange case in a program with jdk1.8,
that I got a null pointer exception in StringBuilder.append() method,
the exact position of the null pointer exception is here,in AbstractStringBuilder class :
public AbstractStringBuilder append(String str) {
if (str == null)
return appendNull();
int len = str.length(); //here
ensureCapacityInternal(count + len);
str.getChars(0, len, value, count);
count += len;
return this;
}
I can’t understand how this can happen, as there is a null check before str.length() called.
And maybe due to the same reason, all the way I tried to print the string content crashed, so I can’t get what string content caused this.
Now, what I want to know is what can cause this, can I build a string content to reproduce this? Thanks for any ideas.
1