Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LANG-1720: Fix Javadoc description of exceptions thrown for existing classes #1160

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/org/apache/commons/lang3/Conversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ public static char binaryToHexDigitMsb0_4bits(final boolean[] src, final int src
if (src.length - srcPos < 4) {
throw new IllegalArgumentException("src.length-srcPos<4: src.length=" + src.length + ", srcPos=" + srcPos);
}
if (srcPos >= 0) {
throw new IllegalArgumentException("srcPos>=0: srcPos=" + srcPos);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not api doc. It's a new exception, and I'm not sure it's correct.

}
if (src[srcPos + 3]) {
if (src[srcPos + 2]) {
if (src[srcPos + 1]) {
Expand Down Expand Up @@ -788,6 +791,7 @@ public static int hexDigitToInt(final char hexDigit) {
* @param nHex the number of Chars to convert
* @return a byte containing the selected bits
* @throws IllegalArgumentException if {@code (nHex-1)*4+dstPos >= 8}
* @throws StringIndexOutOfBoundsException if {@code srcPos < 0}
*/
public static byte hexToByte(final String src, final int srcPos, final byte dstInit, final int dstPos,
final int nHex) {
Expand Down Expand Up @@ -819,6 +823,7 @@ public static byte hexToByte(final String src, final int srcPos, final byte dstI
* @param nHex the number of Chars to convert
* @return an int containing the selected bits
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 32}
* @throws StringIndexOutOfBoundsException if {@code srcPos < 0}
*/
public static int hexToInt(final String src, final int srcPos, final int dstInit, final int dstPos, final int nHex) {
if (0 == nHex) {
Expand Down Expand Up @@ -849,6 +854,7 @@ public static int hexToInt(final String src, final int srcPos, final int dstInit
* @param nHex the number of Chars to convert
* @return a long containing the selected bits
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 64}
* @throws StringIndexOutOfBoundsException if {@code srcPos < 0}
*/
public static long hexToLong(final String src, final int srcPos, final long dstInit, final int dstPos,
final int nHex) {
Expand Down Expand Up @@ -880,6 +886,7 @@ public static long hexToLong(final String src, final int srcPos, final long dstI
* @param nHex the number of Chars to convert
* @return a short containing the selected bits
* @throws IllegalArgumentException if {@code (nHexs-1)*4+dstPos >= 16}
* @throws StringIndexOutOfBoundsException if {@code srcPos < 0}
*/
public static short hexToShort(final String src, final int srcPos, final short dstInit, final int dstPos,
final int nHex) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/apache/commons/lang3/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3916,6 +3916,7 @@ public static String join(final boolean[] array, final char delimiter) {
* the index to stop joining from (exclusive). It is an error to pass in an end index past the end of
* the array
* @return the joined String, {@code null} if null array input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= array.length}
* @since 3.12.0
*/
public static String join(final boolean[] array, final char delimiter, final int startIndex, final int endIndex) {
Expand Down Expand Up @@ -3991,6 +3992,7 @@ public static String join(final byte[] array, final char delimiter) {
* the index to stop joining from (exclusive). It is an error to pass in an end index past the end of
* the array
* @return the joined String, {@code null} if null array input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= array.length}
* @since 3.2
*/
public static String join(final byte[] array, final char delimiter, final int startIndex, final int endIndex) {
Expand Down Expand Up @@ -4066,6 +4068,7 @@ public static String join(final char[] array, final char delimiter) {
* the index to stop joining from (exclusive). It is an error to pass in an end index past the end of
* the array
* @return the joined String, {@code null} if null array input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= array.length}
* @since 3.2
*/
public static String join(final char[] array, final char delimiter, final int startIndex, final int endIndex) {
Expand Down Expand Up @@ -4141,6 +4144,7 @@ public static String join(final double[] array, final char delimiter) {
* the index to stop joining from (exclusive). It is an error to pass in an end index past the end of
* the array
* @return the joined String, {@code null} if null array input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= array.length}
* @since 3.2
*/
public static String join(final double[] array, final char delimiter, final int startIndex, final int endIndex) {
Expand Down Expand Up @@ -4216,6 +4220,7 @@ public static String join(final float[] array, final char delimiter) {
* the index to stop joining from (exclusive). It is an error to pass in an end index past the end of
* the array
* @return the joined String, {@code null} if null array input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= array.length}
* @since 3.2
*/
public static String join(final float[] array, final char delimiter, final int startIndex, final int endIndex) {
Expand Down Expand Up @@ -4418,6 +4423,7 @@ public static String join(final Iterator<?> iterator, final String separator) {
* @param endIndex the index to stop joining from (exclusive). It is
* an error to pass in an end index past the end of the list
* @return the joined String, {@code null} if null list input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= list.size()}
* @since 3.8
*/
public static String join(final List<?> list, final char separator, final int startIndex, final int endIndex) {
Expand Down Expand Up @@ -4456,6 +4462,7 @@ public static String join(final List<?> list, final char separator, final int st
* @param endIndex the index to stop joining from (exclusive). It is
* an error to pass in an end index past the end of the list
* @return the joined String, {@code null} if null list input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= list.size()}
* @since 3.8
*/
public static String join(final List<?> list, final String separator, final int startIndex, final int endIndex) {
Expand Down Expand Up @@ -4728,6 +4735,7 @@ public static String join(final short[] array, final char delimiter) {
* the index to stop joining from (exclusive). It is an error to pass in an end index past the end of
* the array
* @return the joined String, {@code null} if null array input
* @throws ArrayIndexOutOfBoundsException if {@code startIndex < 0 || endIndex >= array.length}
* @since 3.2
*/
public static String join(final short[] array, final char delimiter, final int startIndex, final int endIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ public String replace(final char[] source) {
* @param offset the start offset within the array, must be valid
* @param length the length within the array to be processed, must be valid
* @return the result of the replace operation
* @throws StringIndexOutOfBoundsException if {@code offset < 0 || offset + length >= source.length}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why String instead of array here? If this is the behavior it might be a bug. Change the doc to just IndexOutOfBoundsException for now in case we need to fix this.

*/
public String replace(final char[] source, final int offset, final int length) {
if (source == null) {
Expand Down Expand Up @@ -577,6 +578,7 @@ public String replace(final CharSequence source) {
* @param offset the start offset within the array, must be valid
* @param length the length within the array to be processed, must be valid
* @return the result of the replace operation
* @throws StringIndexOutOfBoundsException if {@code offset < 0 || offset + length >= source.length}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should maybe be IndexOutOfBoundsException

* @since 3.2
*/
public String replace(final CharSequence source, final int offset, final int length) {
Expand Down Expand Up @@ -675,6 +677,7 @@ public String replace(final String source) {
* @param offset the start offset within the array, must be valid
* @param length the length within the array to be processed, must be valid
* @return the result of the replace operation
* @throws StringIndexOutOfBoundsException if {@code offset < 0 || offset + length >= source.length}
*/
public String replace(final String source, final int offset, final int length) {
if (source == null) {
Expand Down Expand Up @@ -717,6 +720,7 @@ public String replace(final StringBuffer source) {
* @param offset the start offset within the array, must be valid
* @param length the length within the array to be processed, must be valid
* @return the result of the replace operation
* @throws StringIndexOutOfBoundsException if {@code offset < 0 || offset + length >= source.length}
*/
public String replace(final StringBuffer source, final int offset, final int length) {
if (source == null) {
Expand Down Expand Up @@ -753,6 +757,7 @@ public boolean replaceIn(final StrBuilder source) {
* @param offset the start offset within the array, must be valid
* @param length the length within the builder to be processed, must be valid
* @return true if altered
* @throws StringIndexOutOfBoundsException if {@code offset < 0 || offset + length >= source.length}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does strike me as possible that some of these exceptions shouldn't be thrown at all. If offset or length are out of bounds, maybe nothing is replaced.

*/
public boolean replaceIn(final StrBuilder source, final int offset, final int length) {
if (source == null) {
Expand Down Expand Up @@ -789,6 +794,7 @@ public boolean replaceIn(final StringBuffer source) {
* @param offset the start offset within the array, must be valid
* @param length the length within the buffer to be processed, must be valid
* @return true if altered
* @throws StringIndexOutOfBoundsException if {@code offset < 0 || offset + length >= source.length}
*/
public boolean replaceIn(final StringBuffer source, final int offset, final int length) {
if (source == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public final String translate(final CharSequence input) {
* @param out Writer to translate the text to
* @return int count of code points consumed
* @throws IOException if and only if the Writer produces an IOException
* @throws StringIndexOutOfBoundsException if {@code index < 0 || index >= input.length()}
*/
public abstract int translate(CharSequence input, int index, Writer out) throws IOException;

Expand Down
Loading