< prev index next >

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Print this page
rev 53655 : imported patch 8218228-The-constructor-StringBuffer-CharSequence-violates-spec-for-negatively-sized-argument

*** 91,107 **** } } /** * Creates an AbstractStringBuilder with the specified coder and with ! * the initial capacity equal to the smaller of (capacity + addition) * and Integer.MAX_VALUE. */ ! AbstractStringBuilder(byte coder, int capacity, int addition) { this.coder = coder; ! capacity = (capacity < Integer.MAX_VALUE - addition) ! ? capacity + addition : Integer.MAX_VALUE; value = (coder == LATIN1) ? new byte[capacity] : StringUTF16.newBytesFor(capacity); } /** --- 91,110 ---- } } /** * Creates an AbstractStringBuilder with the specified coder and with ! * the initial capacity equal to the smaller of (length + addition) * and Integer.MAX_VALUE. */ ! AbstractStringBuilder(byte coder, int length, int addition) { ! if (length < 0) { ! throw new NegativeArraySizeException("Negative length: " + length); ! } this.coder = coder; ! int capacity = (length < Integer.MAX_VALUE - addition) ! ? length + addition : Integer.MAX_VALUE; value = (coder == LATIN1) ? new byte[capacity] : StringUTF16.newBytesFor(capacity); } /**
< prev index next >