mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8218228: The constructor StringBuffer(CharSequence) violates spec for negatively sized argument
Reviewed-by: rriggs, darcy
This commit is contained in:
parent
2324f24c5d
commit
0052dff370
3 changed files with 38 additions and 10 deletions
|
@ -93,13 +93,16 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
|
||||
/**
|
||||
* Creates an AbstractStringBuilder with the specified coder and with
|
||||
* the initial capacity equal to the smaller of (capacity + addition)
|
||||
* the initial capacity equal to the smaller of (length + addition)
|
||||
* and Integer.MAX_VALUE.
|
||||
*/
|
||||
AbstractStringBuilder(byte coder, int capacity, int addition) {
|
||||
AbstractStringBuilder(byte coder, int length, int addition) {
|
||||
if (length < 0) {
|
||||
throw new NegativeArraySizeException("Negative length: " + length);
|
||||
}
|
||||
this.coder = coder;
|
||||
capacity = (capacity < Integer.MAX_VALUE - addition)
|
||||
? capacity + addition : Integer.MAX_VALUE;
|
||||
int capacity = (length < Integer.MAX_VALUE - addition)
|
||||
? length + addition : Integer.MAX_VALUE;
|
||||
value = (coder == LATIN1)
|
||||
? new byte[capacity] : StringUTF16.newBytesFor(capacity);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue