8299600: Use Objects.check*() where appropriate in java.io

Reviewed-by: alanb, bpb
This commit is contained in:
Sergey Tsypanov 2023-01-06 21:01:21 +00:00 committed by Brian Burkhalter
parent 4a95c74b76
commit d086e82b3c
6 changed files with 28 additions and 27 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,6 +26,7 @@
package java.io;
import java.util.Arrays;
import java.util.Objects;
/**
* This class implements a character buffer that can be used as a Writer.
@ -97,10 +98,8 @@ public class CharArrayWriter extends Writer {
* of the given array
*/
public void write(char[] c, int off, int len) {
if ((off < 0) || (off > c.length) || (len < 0) ||
((off + len) > c.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
Objects.checkFromIndexSize(off, len, c.length);
if (len == 0) {
return;
}
synchronized (lock) {