OpenJDK / amber / amber
changeset 15312:4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
Summary: Add blanket null-handling statement to StringBuilder and StringBuffer
Reviewed-by: mduigou
author | jgish |
---|---|
date | Tue, 22 Jan 2013 11:14:13 -0500 |
parents | be0ff4a719bf |
children | 35fafa425a70 |
files | jdk/src/share/classes/java/lang/AbstractStringBuilder.java jdk/src/share/classes/java/lang/String.java jdk/src/share/classes/java/lang/StringBuffer.java jdk/src/share/classes/java/lang/StringBuilder.java |
diffstat | 4 files changed, 18 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/src/share/classes/java/lang/AbstractStringBuilder.java Fri Jan 25 16:13:39 2013 -0800 +++ b/jdk/src/share/classes/java/lang/AbstractStringBuilder.java Tue Jan 22 11:14:13 2013 -0500 @@ -35,6 +35,10 @@ * particular sequence of characters, but the length and content of the * 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 Martin Buchholz * @author Ulf Zibis @@ -334,8 +338,6 @@ * @param srcEnd stop copying at this offset. * @param dst the array to copy the data into. * @param dstBegin offset into {@code dst}. - * @throws NullPointerException if {@code dst} is - * {@code null}. * @throws IndexOutOfBoundsException if any of the following is true: * <ul> * <li>{@code srcBegin} is negative @@ -1282,8 +1284,6 @@ * object, then the index of the first character of the first * such substring is returned; if it does not occur as a * substring, {@code -1} is returned. - * @throws java.lang.NullPointerException if {@code str} is - * {@code null}. */ public int indexOf(String str) { return indexOf(str, 0); @@ -1303,8 +1303,6 @@ * @param fromIndex the index from which to start the search. * @return the index within this string of the first occurrence of the * specified substring, starting at the specified index. - * @throws java.lang.NullPointerException if {@code str} is - * {@code null}. */ public int indexOf(String str, int fromIndex) { return String.indexOf(value, 0, count, str, fromIndex); @@ -1325,8 +1323,6 @@ * within this object, then the index of the first character of * the last such substring is returned. If it does not occur as * a substring, {@code -1} is returned. - * @throws java.lang.NullPointerException if {@code str} is - * {@code null}. */ public int lastIndexOf(String str) { return lastIndexOf(str, count); @@ -1346,8 +1342,6 @@ * @param fromIndex the index to start the search from. * @return the index within this sequence of the last occurrence of the * specified substring. - * @throws java.lang.NullPointerException if {@code str} is - * {@code null}. */ public int lastIndexOf(String str, int fromIndex) { return String.lastIndexOf(value, 0, count, str, fromIndex);
--- a/jdk/src/share/classes/java/lang/String.java Fri Jan 25 16:13:39 2013 -0800 +++ b/jdk/src/share/classes/java/lang/String.java Tue Jan 22 11:14:13 2013 -0500 @@ -33,6 +33,7 @@ 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; @@ -871,6 +872,8 @@ if (srcBegin > srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } + Objects.requireNonNull(dst); + int j = dstBegin; int n = srcEnd; int i = srcBegin; @@ -2112,7 +2115,6 @@ * * @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) { @@ -2219,8 +2221,6 @@ * @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) { @@ -2833,9 +2833,6 @@ * 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 @@ -2865,8 +2862,8 @@ * 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 @@ -2877,9 +2874,6 @@ * 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
--- a/jdk/src/share/classes/java/lang/StringBuffer.java Fri Jan 25 16:13:39 2013 -0800 +++ b/jdk/src/share/classes/java/lang/StringBuffer.java Tue Jan 22 11:14:13 2013 -0500 @@ -77,7 +77,11 @@ * 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 @@ -123,7 +127,6 @@ * {@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); @@ -141,7 +144,6 @@ * {@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) { @@ -228,7 +230,6 @@ } /** - * @throws NullPointerException {@inheritDoc} * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override @@ -584,7 +585,6 @@ } /** - * @throws NullPointerException {@inheritDoc} * @since 1.4 */ @Override @@ -594,7 +594,6 @@ } /** - * @throws NullPointerException {@inheritDoc} * @since 1.4 */ @Override @@ -603,7 +602,6 @@ } /** - * @throws NullPointerException {@inheritDoc} * @since 1.4 */ @Override @@ -613,7 +611,6 @@ } /** - * @throws NullPointerException {@inheritDoc} * @since 1.4 */ @Override
--- a/jdk/src/share/classes/java/lang/StringBuilder.java Fri Jan 25 16:13:39 2013 -0800 +++ b/jdk/src/share/classes/java/lang/StringBuilder.java Tue Jan 22 11:14:13 2013 -0500 @@ -64,6 +64,10 @@ * use by multiple threads. If such synchronization is required then it is * 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 * @see java.lang.StringBuffer * @see java.lang.String @@ -103,7 +107,6 @@ * {@code 16} plus the length of the string argument. * * @param str the initial contents of the buffer. - * @throws NullPointerException if {@code str} is {@code null} */ public StringBuilder(String str) { super(str.length() + 16); @@ -117,7 +120,6 @@ * {@code CharSequence} argument. * * @param seq the sequence to copy. - * @throws NullPointerException if {@code seq} is {@code null} */ public StringBuilder(CharSequence seq) { this(seq.length() + 16); @@ -373,33 +375,21 @@ return this; } - /** - * @throws NullPointerException {@inheritDoc} - */ @Override public int indexOf(String str) { return super.indexOf(str); } - /** - * @throws NullPointerException {@inheritDoc} - */ @Override public int indexOf(String str, int fromIndex) { return super.indexOf(str, fromIndex); } - /** - * @throws NullPointerException {@inheritDoc} - */ @Override public int lastIndexOf(String str) { return super.lastIndexOf(str); } - /** - * @throws NullPointerException {@inheritDoc} - */ @Override public int lastIndexOf(String str, int fromIndex) { return super.lastIndexOf(str, fromIndex);