mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-11 05:59:52 +00:00
8270058: Use Objects.check{Index,FromIndexSize} for java.desktop
Reviewed-by: psadhukhan, pbansal, jdv
This commit is contained in:
parent
64d18d45ef
commit
ea9a59520d
@ -30,6 +30,7 @@ import java.io.File;
|
||||
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 abstract class AudioFloatInputStream {
|
||||
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.Serial;
|
||||
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 class JTabbedPane extends JComponent
|
||||
|
||||
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 @@ class ClippedImageCanvas extends Component implements Printable, 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 @@ class ClippedImageCanvas extends Component implements Printable, Pageable {
|
||||
|
||||
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.Iterator;
|
||||
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,8 +115,7 @@ public class AppletResourceTest {
|
||||
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;
|
||||
}
|
||||
@ -123,8 +123,7 @@ public class AppletResourceTest {
|
||||
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;
|
||||
}
|
||||
@ -132,8 +131,7 @@ public class AppletResourceTest {
|
||||
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 class AppletResourceTest {
|
||||
|
||||
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 class AppletResourceTest {
|
||||
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.awt.image.BufferedImage;
|
||||
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 class ImageReaderReadAll {
|
||||
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 class ImageReaderReadAll {
|
||||
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.Iterator;
|
||||
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,8 +116,7 @@ public class UserPluginMetadataFormatTest implements MetadataTest {
|
||||
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;
|
||||
}
|
||||
@ -124,8 +124,7 @@ public class UserPluginMetadataFormatTest implements MetadataTest {
|
||||
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;
|
||||
}
|
||||
@ -133,8 +132,7 @@ public class UserPluginMetadataFormatTest implements MetadataTest {
|
||||
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 class UserPluginMetadataFormatTest implements MetadataTest {
|
||||
|
||||
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 class UserPluginMetadataFormatTest implements MetadataTest {
|
||||
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user