Merge pull request #50369 from quaff

Closes gh-50369

* pr/50369:
  Polish AppendableByteArray
This commit is contained in:
Phillip Webb
2026-05-12 09:13:32 -07:00
2 changed files with 5 additions and 3 deletions
@@ -25,6 +25,8 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
/**
@@ -36,7 +38,7 @@ import org.springframework.util.Assert;
*/
class AppendableByteArray implements Appendable {
private static ThreadLocal<SoftReference<AppendableByteArray>> cache = new ThreadLocal<>();
private static final ThreadLocal<@Nullable SoftReference<AppendableByteArray>> cache = new ThreadLocal<>();
private static final int DEFAULT_INITIAL_SIZE = 8192;
@@ -66,7 +68,7 @@ class AppendableByteArray implements Appendable {
}
@Override
public AppendableByteArray append(CharSequence charSequence, int start, int end) throws IOException {
public AppendableByteArray append(@Nullable CharSequence charSequence, int start, int end) throws IOException {
return append(((charSequence != null) ? charSequence : "null").subSequence(start, end));
}
@@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class AppendableByteArrayTests {
private static String string = """
private static final String string = """
This is a long(ish) string.
At least it's longer that the initial size and the overflow size.
We can write it out and test if the bytes match.