src/share/classes/java/lang/StringBuffer.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
@@ -75,11 +75,15 @@
* Every string buffer has a capacity. As long as the length of the
* character sequence contained in the string buffer does not exceed
* the capacity, it is not necessary to allocate a new internal
* buffer array. If the internal buffer overflows, it is
* 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
* class designed for use by a single thread, {@link StringBuilder}. The
* {@code StringBuilder} class should generally be used in preference to
* this one, as it supports all of the same operations but it is faster, as
* it performs no synchronization.
@@ -121,11 +125,10 @@
* Constructs a string buffer initialized to the contents of the
* specified string. The initial capacity of the string buffer is
* {@code 16} plus the length of the string argument.
*
* @param str the initial contents of the buffer.
- * @exception NullPointerException if {@code str} is {@code null}
*/
public StringBuffer(String str) {
super(str.length() + 16);
append(str);
}
@@ -139,11 +142,10 @@
* If the length of the specified {@code CharSequence} is
* less than or equal to zero, then an empty buffer of capacity
* {@code 16} is returned.
*
* @param seq the sequence to copy.
- * @exception NullPointerException if {@code seq} is {@code null}
* @since 1.5
*/
public StringBuffer(CharSequence seq) {
this(seq.length() + 16);
append(seq);
@@ -226,11 +228,10 @@
public synchronized int offsetByCodePoints(int index, int codePointOffset) {
return super.offsetByCodePoints(index, codePointOffset);
}
/**
- * @throws NullPointerException {@inheritDoc}
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
@Override
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
int dstBegin)
@@ -582,40 +583,36 @@
super.insert(offset, d);
return this;
}
/**
- * @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
@Override
public int indexOf(String str) {
// Note, synchronization achieved via invocations of other StringBuffer methods
return super.indexOf(str);
}
/**
- * @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
@Override
public synchronized int indexOf(String str, int fromIndex) {
return super.indexOf(str, fromIndex);
}
/**
- * @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
@Override
public int lastIndexOf(String str) {
// Note, synchronization achieved via invocations of other StringBuffer methods
return lastIndexOf(str, count);
}
/**
- * @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
@Override
public synchronized int lastIndexOf(String str, int fromIndex) {
return super.lastIndexOf(str, fromIndex);