I was looking through the source code of this class and I start from append method that is called by StringBUffer.append();
public AbstractStringBuilder append(String str) { if (str == null) str = "null"; int len = str.length(); if (len == 0) return this; int newCount = count + len; if (newCount > value.length) expandCapacity(newCount); // newcount is the new volumn of a char array str.getChars(0, len, value, count); count = newCount; return this; } Then I went deeper into enpandCapacity method
void expandCapacity(int minimumCapacity) { int newCapacity = (value.length + 1) * 2; //here value is a char array if (newCapacity < 0) { // Why is newCapacity less than 0? // Is that possible? When it will be possible? newCapacity = Integer.MAX_VALUE; } else if (minimumCapacity > newCapacity) { newCapacity = minimumCapacity; } value = Arrays.copyOf(value, newCapacity); } Why is newCapacity less than 0? Is that possible? When it will be possible?
MAX_VALUE + 1 == MIN_VALUEInteger.MAX_VALUE * 2, which evaluates to-2.