src/share/classes/java/lang/String.java
Print this page
rev 6406 : 4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
Summary: Add blanket null-handling statement to StringBuilder and StringBuffer
Reviewed-by: mduigou
@@ -31,10 +31,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Formatter;
import java.util.Locale;
+import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/**
@@ -869,10 +870,12 @@
throw new StringIndexOutOfBoundsException(srcEnd);
}
if (srcBegin > srcEnd) {
throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
}
+ Objects.requireNonNull(dst);
+
int j = dstBegin;
int n = srcEnd;
int i = srcBegin;
char[] val = value; /* avoid getfield opcode */
@@ -2110,11 +2113,10 @@
* Returns true if and only if this string contains the specified
* sequence of char values.
*
* @param s the sequence to search for
* @return true if this string contains {@code s}, false otherwise
- * @throws NullPointerException if {@code s} is {@code null}
* @since 1.5
*/
public boolean contains(CharSequence s) {
return indexOf(s.toString()) > -1;
}
@@ -2217,12 +2219,10 @@
* "ba" rather than "ab".
*
* @param target The sequence of char values to be replaced
* @param replacement The replacement sequence of char values
* @return The resulting string
- * @throws NullPointerException if {@code target} or
- * {@code replacement} is {@code null}.
* @since 1.5
*/
public String replace(CharSequence target, CharSequence replacement) {
return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(
this).replaceAll(Matcher.quoteReplacement(replacement.toString()));
@@ -2831,13 +2831,10 @@
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification.
*
- * @throws NullPointerException
- * If the {@code format} is {@code null}
- *
* @return A formatted string
*
* @see java.util.Formatter
* @since 1.5
*/
@@ -2863,25 +2860,22 @@
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* <cite>The Java™ Virtual Machine Specification</cite>.
* The behaviour on a
- * {@code null} argument depends on the <a
- * href="../util/Formatter.html#syntax">conversion</a>.
+ * {@code null} argument depends on the
+ * <a href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws java.util.IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification
*
- * @throws NullPointerException
- * If the {@code format} is {@code null}
- *
* @return A formatted string
*
* @see java.util.Formatter
* @since 1.5
*/