RFR: 8351443: Improve robustness of StringBuilder [v6]

Roger Riggs rriggs at openjdk.org
Fri May 9 15:23:36 UTC 2025


On Tue, 6 May 2025 16:18:11 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Apply reviewer suggestions for typos, javadoc, and copyright dates.
>
> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 270:
> 
>> 268:     private static byte[] ensureCapacityNewCoder(byte[] value, byte coder, int count,
>> 269:                                                  int minimumCapacity, byte newCoder) {
>> 270:         assert coder == newCoder || newCoder == UTF16 : "bad new coder UTF16 -> LATIN1";
> 
> I recommend an additional assertion `count <= minimumCapacity`; even though all callers ensure this currently, in case this is accidentally violated, we are sending dangerous arguments to `StringLatin1.inflate`.
> 
> Also, the message string of assertion can include the `coder` and `newCoder` values. Same for the other assertions we add.

Added the assertion(s) without the extra message formatting overhead/codesize.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24967#discussion_r2081918105


More information about the core-libs-dev mailing list