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

Print this page

        

*** 410,420 **** @Override @HotSpotIntrinsicCandidate public String toString() { // Create a copy, don't share the array ! return new String(value, 0, count); } /** * Save the state of the {@code StringBuilder} instance to a stream * (that is, serialize it). --- 410,421 ---- @Override @HotSpotIntrinsicCandidate public String toString() { // Create a copy, don't share the array ! return isLatin1() ? StringLatin1.newString(value, 0, count) ! : StringUTF16.newStringSB(value, 0, count); } /** * Save the state of the {@code StringBuilder} instance to a stream * (that is, serialize it).
*** 428,447 **** */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); s.writeInt(count); ! s.writeObject(value); } /** * readObject is called to restore the state of the StringBuffer from * a stream. */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); count = s.readInt(); ! value = (char[]) s.readObject(); } } --- 429,455 ---- */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.defaultWriteObject(); s.writeInt(count); ! char[] val = new char[capacity()]; ! if (isLatin1()) { ! StringLatin1.getChars(value, 0, count, val, 0); ! } else { ! StringUTF16.getChars(value, 0, count, val, 0); ! } ! s.writeObject(val); } /** * readObject is called to restore the state of the StringBuffer from * a stream. */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); count = s.readInt(); ! char[] val = (char[]) s.readObject(); ! initBytes(val, 0, val.length); } }