From 6035b45f8a2f74b7b3f59f86d3ecaddd1d89c3c3 Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Fri, 4 Oct 2024 12:31:33 -0400 Subject: [PATCH] Annotate the new `repeat` API on `StringBuilder` and friends. I'm not sure that annotation in `AbstractStringBuilder` matter much, but I'm not ruling it out that an expression could have that implicit type if you wrote something like `b ? new StringBuilder() : new StringBuffer()`. And anyway, it was nice to keep `AbstractStringBuilder` up to date while having reference to its implementation so that I could then easily cross-reference between it and the subclasses. --- .../share/classes/java/lang/AbstractStringBuilder.java | 2 +- src/java.base/share/classes/java/lang/StringBuffer.java | 2 +- src/java.base/share/classes/java/lang/StringBuilder.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java index 3b1fcc72eaf..6efb1983f6a 100644 --- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java @@ -1964,7 +1964,7 @@ public AbstractStringBuilder repeat(int codePoint, int count) { * * @since 21 */ - public AbstractStringBuilder repeat(CharSequence cs, int count) { + public AbstractStringBuilder repeat(@Nullable CharSequence cs, int count) { if (count < 0) { throw new IllegalArgumentException("count is negative: " + count); } else if (count == 0) { diff --git a/src/java.base/share/classes/java/lang/StringBuffer.java b/src/java.base/share/classes/java/lang/StringBuffer.java index fe59ed4ea2f..f0b80a5dbf7 100644 --- a/src/java.base/share/classes/java/lang/StringBuffer.java +++ b/src/java.base/share/classes/java/lang/StringBuffer.java @@ -735,7 +735,7 @@ public synchronized StringBuffer repeat(int codePoint, int count) { * @since 21 */ @Override - public synchronized StringBuffer repeat(CharSequence cs, int count) { + public synchronized StringBuffer repeat(@Nullable CharSequence cs, int count) { toStringCache = null; super.repeat(cs, count); return this; diff --git a/src/java.base/share/classes/java/lang/StringBuilder.java b/src/java.base/share/classes/java/lang/StringBuilder.java index 441688f5465..b860c9b28b0 100644 --- a/src/java.base/share/classes/java/lang/StringBuilder.java +++ b/src/java.base/share/classes/java/lang/StringBuilder.java @@ -471,7 +471,7 @@ public StringBuilder repeat(int codePoint, int count) { * @since 21 */ @Override - public StringBuilder repeat(CharSequence cs, int count) { + public StringBuilder repeat(@Nullable CharSequence cs, int count) { super.repeat(cs, count); return this; }