Skip to content
Permalink
Browse files
8270058: Use Objects.check{Index,FromIndexSize} for java.desktop
Reviewed-by: psadhukhan, pbansal, jdv
  • Loading branch information
Yi Yang committed Aug 5, 2021
1 parent 64d18d4 commit ea9a59520de45fe1c2a6706b2a924cbc856a06c6
@@ -30,6 +30,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Objects;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@@ -81,8 +82,7 @@ public long getFrameLength() {
public int read(float[] b, int off, int len) throws IOException {
if (b == null)
throw new NullPointerException();
if (off < 0 || len < 0 || len > b.length - off)
throw new IndexOutOfBoundsException();
Objects.checkFromIndexSize(off, len, b.length);
if (pos >= buffer_len)
return -1;
if (len == 0)
@@ -45,6 +45,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Objects;

import javax.accessibility.Accessible;
import javax.accessibility.AccessibleComponent;
@@ -1790,7 +1791,7 @@ public String getToolTipText(MouseEvent event) {

private void checkIndex(int index) {
if (index < 0 || index >= pages.size()) {
throw new IndexOutOfBoundsException("Index: "+index+", Tab count: "+pages.size());
throw new IndexOutOfBoundsException("Index: " + index + ", Tab count: " + pages.size());
}
}

@@ -29,6 +29,7 @@
*/

import java.io.*;
import java.util.Objects;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
@@ -196,10 +197,7 @@ void setPrinterJob(PrinterJob job, boolean pageable) {

public PageFormat getPageFormat(int pageIndex)
throws IndexOutOfBoundsException {

if (pageIndex < 0 || pageIndex >= getNumberOfPages()) {
throw new IndexOutOfBoundsException();
}
Objects.checkIndex(pageIndex, getNumberOfPages());

PageFormat pf = myPrinterJob.defaultPage();
switch (pageIndex % 2) {
@@ -225,10 +223,8 @@ String getOrientStr(PageFormat pf) {

public Printable getPrintable(int pageIndex)
throws IndexOutOfBoundsException {
Objects.checkIndex(pageIndex, getNumberOfPages());

if (pageIndex < 0 || pageIndex >= getNumberOfPages()) {
throw new IndexOutOfBoundsException();
}
if (pageIndex < 2) {
paintSquares = true;
} else {
@@ -37,6 +37,7 @@
import java.util.ListResourceBundle;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.Vector;

import javax.imageio.IIOException;
@@ -114,26 +115,23 @@ public int getNumImages(boolean allowSearch) throws IOException {
public int getWidth(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);

return 10;
}

public int getHeight(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);

return 15;
}

public Iterator getImageTypes(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);

Vector imageTypes = new Vector();
imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
@@ -150,8 +148,7 @@ public IIOMetadata getImageMetadata(int imageIndex)

if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);
if (seekForwardOnly) {
if (imageIndex < minIndex)
throw new IndexOutOfBoundsException();
@@ -165,8 +162,7 @@ public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);
if (seekForwardOnly) {
if (imageIndex < minIndex)
throw new IndexOutOfBoundsException();
@@ -32,6 +32,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Objects;
import java.util.Vector;

import javax.imageio.IIOImage;
@@ -87,8 +88,7 @@ public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 1 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 1);
if (seekForwardOnly) {
if (imageIndex < minIndex)
throw new IndexOutOfBoundsException();
@@ -101,8 +101,7 @@ public BufferedImage read(int imageIndex, ImageReadParam param)
public Iterator getImageTypes(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 1 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 1);

Vector imageTypes = new Vector();
imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
@@ -39,6 +39,7 @@
import java.util.ListResourceBundle;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Objects;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
@@ -115,26 +116,23 @@ public int getNumImages(boolean allowSearch) throws IOException {
public int getWidth(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);

return 10;
}

public int getHeight(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);

return 15;
}

public Iterator getImageTypes(int imageIndex) throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);

Vector imageTypes = new Vector();
imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType
@@ -150,8 +148,7 @@ public IIOMetadata getImageMetadata(int imageIndex) throws IOException {

if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);
if (seekForwardOnly) {
if (imageIndex < minIndex)
throw new IndexOutOfBoundsException();
@@ -169,8 +166,7 @@ public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {
if (input == null)
throw new IllegalStateException();
if (imageIndex >= 5 || imageIndex < 0)
throw new IndexOutOfBoundsException();
Objects.checkIndex(imageIndex, 5);
if (seekForwardOnly) {
if (imageIndex < minIndex)
throw new IndexOutOfBoundsException();

1 comment on commit ea9a595

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on ea9a595 Aug 5, 2021

Please sign in to comment.