8161558: ListIterator should not discard cause on exception

Reviewed-by: smarks
This commit is contained in:
Kiran Sidhartha Ravikumar 2020-03-13 18:38:07 +00:00
parent cd7d175001
commit fa069be2f2
3 changed files with 143 additions and 2 deletions

View file

@ -374,7 +374,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L
return next;
} catch (IndexOutOfBoundsException e) {
checkForComodification();
throw new NoSuchElementException();
throw new NoSuchElementException(e);
}
}
@ -418,7 +418,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L
return previous;
} catch (IndexOutOfBoundsException e) {
checkForComodification();
throw new NoSuchElementException();
throw new NoSuchElementException(e);
}
}

View file

@ -46,6 +46,33 @@ public class NoSuchElementException extends RuntimeException {
super();
}
/**
* Constructs a {@code NoSuchElementException} with the specified detail
* message and cause.
*
* @param s the detail message, or null
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method), or null
* @since 15
*/
public NoSuchElementException(String s, Throwable cause) {
super(s, cause);
}
/**
* Constructs a {@code NoSuchElementException} with the specified cause.
* The detail message is set to {@code (cause == null ? null :
* cause.toString())} (which typically contains the class and
* detail message of {@code cause}).
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method)
* @since 15
*/
public NoSuchElementException(Throwable cause) {
super(cause);
}
/**
* Constructs a {@code NoSuchElementException}, saving a reference
* to the error message string {@code s} for later retrieval by the