diff --git a/core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java b/core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java index 94232139b3..74c0f370d3 100644 --- a/core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java +++ b/core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java @@ -3254,12 +3254,10 @@ public String readString() { char[] strBuf = this.strBuf; if (strBuf == null) { strBuf = new char[stroff + 512]; - this.strBuf = strBuf; } else if (stroff > strBuf.length) { - int newCapacity = newCapacity(stroff, strBuf.length); - strBuf = new char[newCapacity]; - this.strBuf = strBuf; + strBuf = new char[newCapacity(stroff, strBuf.length)]; } + this.strBuf = strBuf; System.arraycopy(chars, start, strBuf, 0, stroff); while (true) { @@ -3272,6 +3270,7 @@ public String readString() { if (stroff + 4 >= strBuf.length) { strBuf = Arrays.copyOf(strBuf, newCapacity(stroff + 4, strBuf.length)); + this.strBuf = strBuf; } IOUtils.putLongLE(strBuf, stroff, v); @@ -3300,6 +3299,7 @@ public String readString() { } if (stroff == strBuf.length) { strBuf = Arrays.copyOf(strBuf, newCapacity(stroff + 1, strBuf.length)); + this.strBuf = strBuf; } strBuf[stroff++] = c; offset++;