提交 448b0d97 编写于 作者: J jgish

4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent

Summary: Add blanket null-handling statement to StringBuilder and StringBuffer
Reviewed-by: mduigou
上级 480bafd2
...@@ -35,6 +35,10 @@ import java.util.Arrays; ...@@ -35,6 +35,10 @@ import java.util.Arrays;
* particular sequence of characters, but the length and content of the * particular sequence of characters, but the length and content of the
* sequence can be changed through certain method calls. * sequence can be changed through certain method calls.
* *
* <p>Unless otherwise noted, passing a {@code null} argument to a constructor
* or method in this class will cause a {@link NullPointerException} to be
* thrown.
*
* @author Michael McCloskey * @author Michael McCloskey
* @author Martin Buchholz * @author Martin Buchholz
* @author Ulf Zibis * @author Ulf Zibis
...@@ -334,8 +338,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { ...@@ -334,8 +338,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
* @param srcEnd stop copying at this offset. * @param srcEnd stop copying at this offset.
* @param dst the array to copy the data into. * @param dst the array to copy the data into.
* @param dstBegin offset into {@code dst}. * @param dstBegin offset into {@code dst}.
* @throws NullPointerException if {@code dst} is
* {@code null}.
* @throws IndexOutOfBoundsException if any of the following is true: * @throws IndexOutOfBoundsException if any of the following is true:
* <ul> * <ul>
* <li>{@code srcBegin} is negative * <li>{@code srcBegin} is negative
...@@ -1282,8 +1284,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { ...@@ -1282,8 +1284,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
* object, then the index of the first character of the first * object, then the index of the first character of the first
* such substring is returned; if it does not occur as a * such substring is returned; if it does not occur as a
* substring, {@code -1} is returned. * substring, {@code -1} is returned.
* @throws java.lang.NullPointerException if {@code str} is
* {@code null}.
*/ */
public int indexOf(String str) { public int indexOf(String str) {
return indexOf(str, 0); return indexOf(str, 0);
...@@ -1303,8 +1303,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { ...@@ -1303,8 +1303,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
* @param fromIndex the index from which to start the search. * @param fromIndex the index from which to start the search.
* @return the index within this string of the first occurrence of the * @return the index within this string of the first occurrence of the
* specified substring, starting at the specified index. * specified substring, starting at the specified index.
* @throws java.lang.NullPointerException if {@code str} is
* {@code null}.
*/ */
public int indexOf(String str, int fromIndex) { public int indexOf(String str, int fromIndex) {
return String.indexOf(value, 0, count, str, fromIndex); return String.indexOf(value, 0, count, str, fromIndex);
...@@ -1325,8 +1323,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { ...@@ -1325,8 +1323,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
* within this object, then the index of the first character of * within this object, then the index of the first character of
* the last such substring is returned. If it does not occur as * the last such substring is returned. If it does not occur as
* a substring, {@code -1} is returned. * a substring, {@code -1} is returned.
* @throws java.lang.NullPointerException if {@code str} is
* {@code null}.
*/ */
public int lastIndexOf(String str) { public int lastIndexOf(String str) {
return lastIndexOf(str, count); return lastIndexOf(str, count);
...@@ -1346,8 +1342,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { ...@@ -1346,8 +1342,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
* @param fromIndex the index to start the search from. * @param fromIndex the index to start the search from.
* @return the index within this sequence of the last occurrence of the * @return the index within this sequence of the last occurrence of the
* specified substring. * specified substring.
* @throws java.lang.NullPointerException if {@code str} is
* {@code null}.
*/ */
public int lastIndexOf(String str, int fromIndex) { public int lastIndexOf(String str, int fromIndex) {
return String.lastIndexOf(value, 0, count, str, fromIndex); return String.lastIndexOf(value, 0, count, str, fromIndex);
......
...@@ -33,6 +33,7 @@ import java.util.Arrays; ...@@ -33,6 +33,7 @@ import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Formatter; import java.util.Formatter;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
...@@ -871,6 +872,8 @@ public final class String ...@@ -871,6 +872,8 @@ public final class String
if (srcBegin > srcEnd) { if (srcBegin > srcEnd) {
throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
} }
Objects.requireNonNull(dst);
int j = dstBegin; int j = dstBegin;
int n = srcEnd; int n = srcEnd;
int i = srcBegin; int i = srcBegin;
...@@ -2112,7 +2115,6 @@ public final class String ...@@ -2112,7 +2115,6 @@ public final class String
* *
* @param s the sequence to search for * @param s the sequence to search for
* @return true if this string contains {@code s}, false otherwise * @return true if this string contains {@code s}, false otherwise
* @throws NullPointerException if {@code s} is {@code null}
* @since 1.5 * @since 1.5
*/ */
public boolean contains(CharSequence s) { public boolean contains(CharSequence s) {
...@@ -2219,8 +2221,6 @@ public final class String ...@@ -2219,8 +2221,6 @@ public final class String
* @param target The sequence of char values to be replaced * @param target The sequence of char values to be replaced
* @param replacement The replacement sequence of char values * @param replacement The replacement sequence of char values
* @return The resulting string * @return The resulting string
* @throws NullPointerException if {@code target} or
* {@code replacement} is {@code null}.
* @since 1.5 * @since 1.5
*/ */
public String replace(CharSequence target, CharSequence replacement) { public String replace(CharSequence target, CharSequence replacement) {
...@@ -2833,9 +2833,6 @@ public final class String ...@@ -2833,9 +2833,6 @@ public final class String
* href="../util/Formatter.html#detail">Details</a> section of the * href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification. * formatter class specification.
* *
* @throws NullPointerException
* If the {@code format} is {@code null}
*
* @return A formatted string * @return A formatted string
* *
* @see java.util.Formatter * @see java.util.Formatter
...@@ -2865,8 +2862,8 @@ public final class String ...@@ -2865,8 +2862,8 @@ public final class String
* limited by the maximum dimension of a Java array as defined by * limited by the maximum dimension of a Java array as defined by
* <cite>The Java&trade; Virtual Machine Specification</cite>. * <cite>The Java&trade; Virtual Machine Specification</cite>.
* The behaviour on a * The behaviour on a
* {@code null} argument depends on the <a * {@code null} argument depends on the
* href="../util/Formatter.html#syntax">conversion</a>. * <a href="../util/Formatter.html#syntax">conversion</a>.
* *
* @throws java.util.IllegalFormatException * @throws java.util.IllegalFormatException
* If a format string contains an illegal syntax, a format * If a format string contains an illegal syntax, a format
...@@ -2877,9 +2874,6 @@ public final class String ...@@ -2877,9 +2874,6 @@ public final class String
* href="../util/Formatter.html#detail">Details</a> section of the * href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification * formatter class specification
* *
* @throws NullPointerException
* If the {@code format} is {@code null}
*
* @return A formatted string * @return A formatted string
* *
* @see java.util.Formatter * @see java.util.Formatter
......
...@@ -77,7 +77,11 @@ package java.lang; ...@@ -77,7 +77,11 @@ package java.lang;
* the capacity, it is not necessary to allocate a new internal * the capacity, it is not necessary to allocate a new internal
* buffer array. If the internal buffer overflows, it is * buffer array. If the internal buffer overflows, it is
* automatically made larger. * automatically made larger.
* * <p>
* Unless otherwise noted, passing a {@code null} argument to a constructor
* or method in this class will cause a {@link NullPointerException} to be
* thrown.
* <p>
* As of release JDK 5, this class has been supplemented with an equivalent * As of release JDK 5, this class has been supplemented with an equivalent
* class designed for use by a single thread, {@link StringBuilder}. The * class designed for use by a single thread, {@link StringBuilder}. The
* {@code StringBuilder} class should generally be used in preference to * {@code StringBuilder} class should generally be used in preference to
...@@ -123,7 +127,6 @@ package java.lang; ...@@ -123,7 +127,6 @@ package java.lang;
* {@code 16} plus the length of the string argument. * {@code 16} plus the length of the string argument.
* *
* @param str the initial contents of the buffer. * @param str the initial contents of the buffer.
* @exception NullPointerException if {@code str} is {@code null}
*/ */
public StringBuffer(String str) { public StringBuffer(String str) {
super(str.length() + 16); super(str.length() + 16);
...@@ -141,7 +144,6 @@ package java.lang; ...@@ -141,7 +144,6 @@ package java.lang;
* {@code 16} is returned. * {@code 16} is returned.
* *
* @param seq the sequence to copy. * @param seq the sequence to copy.
* @exception NullPointerException if {@code seq} is {@code null}
* @since 1.5 * @since 1.5
*/ */
public StringBuffer(CharSequence seq) { public StringBuffer(CharSequence seq) {
...@@ -228,7 +230,6 @@ package java.lang; ...@@ -228,7 +230,6 @@ package java.lang;
} }
/** /**
* @throws NullPointerException {@inheritDoc}
* @throws IndexOutOfBoundsException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc}
*/ */
@Override @Override
...@@ -584,7 +585,6 @@ package java.lang; ...@@ -584,7 +585,6 @@ package java.lang;
} }
/** /**
* @throws NullPointerException {@inheritDoc}
* @since 1.4 * @since 1.4
*/ */
@Override @Override
...@@ -594,7 +594,6 @@ package java.lang; ...@@ -594,7 +594,6 @@ package java.lang;
} }
/** /**
* @throws NullPointerException {@inheritDoc}
* @since 1.4 * @since 1.4
*/ */
@Override @Override
...@@ -603,7 +602,6 @@ package java.lang; ...@@ -603,7 +602,6 @@ package java.lang;
} }
/** /**
* @throws NullPointerException {@inheritDoc}
* @since 1.4 * @since 1.4
*/ */
@Override @Override
...@@ -613,7 +611,6 @@ package java.lang; ...@@ -613,7 +611,6 @@ package java.lang;
} }
/** /**
* @throws NullPointerException {@inheritDoc}
* @since 1.4 * @since 1.4
*/ */
@Override @Override
......
...@@ -64,6 +64,10 @@ package java.lang; ...@@ -64,6 +64,10 @@ package java.lang;
* use by multiple threads. If such synchronization is required then it is * use by multiple threads. If such synchronization is required then it is
* recommended that {@link java.lang.StringBuffer} be used. * recommended that {@link java.lang.StringBuffer} be used.
* *
* <p>Unless otherwise noted, passing a {@code null} argument to a constructor
* or method in this class will cause a {@link NullPointerException} to be
* thrown.
*
* @author Michael McCloskey * @author Michael McCloskey
* @see java.lang.StringBuffer * @see java.lang.StringBuffer
* @see java.lang.String * @see java.lang.String
...@@ -103,7 +107,6 @@ public final class StringBuilder ...@@ -103,7 +107,6 @@ public final class StringBuilder
* {@code 16} plus the length of the string argument. * {@code 16} plus the length of the string argument.
* *
* @param str the initial contents of the buffer. * @param str the initial contents of the buffer.
* @throws NullPointerException if {@code str} is {@code null}
*/ */
public StringBuilder(String str) { public StringBuilder(String str) {
super(str.length() + 16); super(str.length() + 16);
...@@ -117,7 +120,6 @@ public final class StringBuilder ...@@ -117,7 +120,6 @@ public final class StringBuilder
* {@code CharSequence} argument. * {@code CharSequence} argument.
* *
* @param seq the sequence to copy. * @param seq the sequence to copy.
* @throws NullPointerException if {@code seq} is {@code null}
*/ */
public StringBuilder(CharSequence seq) { public StringBuilder(CharSequence seq) {
this(seq.length() + 16); this(seq.length() + 16);
...@@ -373,33 +375,21 @@ public final class StringBuilder ...@@ -373,33 +375,21 @@ public final class StringBuilder
return this; return this;
} }
/**
* @throws NullPointerException {@inheritDoc}
*/
@Override @Override
public int indexOf(String str) { public int indexOf(String str) {
return super.indexOf(str); return super.indexOf(str);
} }
/**
* @throws NullPointerException {@inheritDoc}
*/
@Override @Override
public int indexOf(String str, int fromIndex) { public int indexOf(String str, int fromIndex) {
return super.indexOf(str, fromIndex); return super.indexOf(str, fromIndex);
} }
/**
* @throws NullPointerException {@inheritDoc}
*/
@Override @Override
public int lastIndexOf(String str) { public int lastIndexOf(String str) {
return super.lastIndexOf(str); return super.lastIndexOf(str);
} }
/**
* @throws NullPointerException {@inheritDoc}
*/
@Override @Override
public int lastIndexOf(String str, int fromIndex) { public int lastIndexOf(String str, int fromIndex) {
return super.lastIndexOf(str, fromIndex); return super.lastIndexOf(str, fromIndex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册