8302664: Fix several incorrect usages of Preconditions.checkFromIndexSize

Reviewed-by: djelinski, dfuchs, alanb
This commit is contained in:
Jaikiran Pai 2023-02-18 00:48:29 +00:00
parent 6b082fb3c6
commit 43cf8b3d80
8 changed files with 19 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -9687,7 +9687,7 @@ class Character implements java.io.Serializable, Comparable<Character>, Constabl
* @since 1.5 * @since 1.5
*/ */
public static int codePointCount(char[] a, int offset, int count) { public static int codePointCount(char[] a, int offset, int count) {
Objects.checkFromIndexSize(count, offset, a.length); Objects.checkFromIndexSize(offset, count, a.length);
return codePointCountImpl(a, offset, count); return codePointCountImpl(a, offset, count);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -932,7 +932,7 @@ public class Base64 {
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, int off, int len) throws IOException {
if (closed) if (closed)
throw new IOException("Stream is closed"); throw new IOException("Stream is closed");
Preconditions.checkFromIndexSize(len, off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, b.length, Preconditions.AIOOBE_FORMATTER);
if (len == 0) if (len == 0)
return; return;
if (leftover != 0) { if (leftover != 0) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2020, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -76,7 +76,7 @@ public class Adler32 implements Checksum {
if (b == null) { if (b == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Preconditions.checkFromIndexSize(len, off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, b.length, Preconditions.AIOOBE_FORMATTER);
adler = updateBytes(adler, b, off, len); adler = updateBytes(adler, b, off, len);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2020, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -75,7 +75,7 @@ public class CRC32 implements Checksum {
if (b == null) { if (b == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Preconditions.checkFromIndexSize(len, off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, b.length, Preconditions.AIOOBE_FORMATTER);
crc = updateBytes(crc, b, off, len); crc = updateBytes(crc, b, off, len);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -150,7 +150,7 @@ public final class CRC32C implements Checksum {
if (b == null) { if (b == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Preconditions.checkFromIndexSize(len, off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, b.length, Preconditions.AIOOBE_FORMATTER);
crc = updateBytes(crc, b, off, (off + len)); crc = updateBytes(crc, b, off, (off + len));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1996, 2022, 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -232,7 +232,7 @@ public class Deflater {
* @see Deflater#needsInput * @see Deflater#needsInput
*/ */
public void setInput(byte[] input, int off, int len) { public void setInput(byte[] input, int off, int len) {
Preconditions.checkFromIndexSize(len, off, input.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, input.length, Preconditions.AIOOBE_FORMATTER);
synchronized (zsRef) { synchronized (zsRef) {
this.input = null; this.input = null;
this.inputArray = input; this.inputArray = input;
@ -297,7 +297,7 @@ public class Deflater {
* @see Inflater#getAdler() * @see Inflater#getAdler()
*/ */
public void setDictionary(byte[] dictionary, int off, int len) { public void setDictionary(byte[] dictionary, int off, int len) {
Preconditions.checkFromIndexSize(len, off, dictionary.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, dictionary.length, Preconditions.AIOOBE_FORMATTER);
synchronized (zsRef) { synchronized (zsRef) {
ensureOpen(); ensureOpen();
setDictionary(zsRef.address(), dictionary, off, len); setDictionary(zsRef.address(), dictionary, off, len);
@ -556,7 +556,7 @@ public class Deflater {
* @since 1.7 * @since 1.7
*/ */
public int deflate(byte[] output, int off, int len, int flush) { public int deflate(byte[] output, int off, int len, int flush) {
Preconditions.checkFromIndexSize(len, off, output.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, output.length, Preconditions.AIOOBE_FORMATTER);
if (flush != NO_FLUSH && flush != SYNC_FLUSH && flush != FULL_FLUSH) { if (flush != NO_FLUSH && flush != SYNC_FLUSH && flush != FULL_FLUSH) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View File

@ -154,7 +154,7 @@ public class Inflater {
* @see Inflater#needsInput * @see Inflater#needsInput
*/ */
public void setInput(byte[] input, int off, int len) { public void setInput(byte[] input, int off, int len) {
Preconditions.checkFromIndexSize(len, off, input.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, input.length, Preconditions.AIOOBE_FORMATTER);
synchronized (zsRef) { synchronized (zsRef) {
this.input = null; this.input = null;
this.inputArray = input; this.inputArray = input;
@ -219,7 +219,7 @@ public class Inflater {
* @see Inflater#getAdler * @see Inflater#getAdler
*/ */
public void setDictionary(byte[] dictionary, int off, int len) { public void setDictionary(byte[] dictionary, int off, int len) {
Preconditions.checkFromIndexSize(len, off, dictionary.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, dictionary.length, Preconditions.AIOOBE_FORMATTER);
synchronized (zsRef) { synchronized (zsRef) {
ensureOpen(); ensureOpen();
setDictionary(zsRef.address(), dictionary, off, len); setDictionary(zsRef.address(), dictionary, off, len);
@ -363,7 +363,7 @@ public class Inflater {
public int inflate(byte[] output, int off, int len) public int inflate(byte[] output, int off, int len)
throws DataFormatException throws DataFormatException
{ {
Preconditions.checkFromIndexSize(len, off, output.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkFromIndexSize(off, len, output.length, Preconditions.AIOOBE_FORMATTER);
synchronized (zsRef) { synchronized (zsRef) {
ensureOpen(); ensureOpen();
ByteBuffer input = this.input; ByteBuffer input = this.input;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -266,7 +266,7 @@ class Request {
assert channel.isBlocking(); assert channel.isBlocking();
Objects.checkFromIndexSize(srclen, off, b.length); Objects.checkFromIndexSize(off, srclen, b.length);
if (reset) { /* satisfy from markBuf */ if (reset) { /* satisfy from markBuf */
canreturn = markBuf.remaining (); canreturn = markBuf.remaining ();