Skip to content

Commit adb860e

Browse files
committed
8255800: Raster creation methods need some specification clean up
Reviewed-by: serb
1 parent eab8455 commit adb860e

5 files changed

Lines changed: 1459 additions & 70 deletions

File tree

src/java.desktop/share/classes/java/awt/image/BandedSampleModel.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -78,8 +78,13 @@ public final class BandedSampleModel extends ComponentSampleModel
7878
* @param h The height (in pixels) of the region of image
7979
* data described.
8080
* @param numBands The number of bands for the image data.
81+
* @throws IllegalArgumentException if {@code w} and {@code h}
82+
* are not both greater than 0
83+
* @throws IllegalArgumentException if the product of {@code w}
84+
* and {@code h} is greater than {@code Integer.MAX_VALUE}
85+
* @throws IllegalArgumentException if {@code numBands} is not > 0
8186
* @throws IllegalArgumentException if {@code dataType} is not
82-
* one of the supported data types
87+
* one of the supported data types for this sample model.
8388
*/
8489
public BandedSampleModel(int dataType, int w, int h, int numBands) {
8590
super(dataType, w, h, 1, w,
@@ -100,8 +105,21 @@ public BandedSampleModel(int dataType, int w, int h, int numBands) {
100105
* @param scanlineStride The line stride of the of the image data.
101106
* @param bankIndices The bank index for each band.
102107
* @param bandOffsets The band offset for each band.
108+
* @throws IllegalArgumentException if {@code w} and {@code h}
109+
* are not both greater than 0
110+
* @throws IllegalArgumentException if the product of {@code w}
111+
* and {@code h} is greater than {@code Integer.MAX_VALUE}
112+
* @throws IllegalArgumentException if {@code scanlineStride} is less than 0
113+
* @throws NullPointerException if {@code bankIndices} is {@code null}
114+
* @throws NullPointerException if {@code bandOffsets} is {@code null}
115+
* @throws IllegalArgumentException if {@code bandOffsets.length} is 0
116+
* @throws IllegalArgumentException if the length of
117+
* {@code bankIndices} does not equal the length of
118+
* {@code bandOffsets}
119+
* @throws IllegalArgumentException if any of the bank indices
120+
* of {@code bandIndices} is less than 0
103121
* @throws IllegalArgumentException if {@code dataType} is not
104-
* one of the supported data types
122+
* one of the supported data types for this sample model
105123
*/
106124
public BandedSampleModel(int dataType,
107125
int w, int h,
@@ -853,6 +871,9 @@ public void setSamples(int x, int y, int w, int h, int b,
853871
}
854872

855873
private static int[] createOffsetArray(int numBands) {
874+
if (numBands <= 0) {
875+
throw new IllegalArgumentException("numBands must be > 0");
876+
}
856877
int[] bandOffsets = new int[numBands];
857878
for (int i=0; i < numBands; i++) {
858879
bandOffsets[i] = 0;
@@ -861,6 +882,9 @@ private static int[] createOffsetArray(int numBands) {
861882
}
862883

863884
private static int[] createIndicesArray(int numBands) {
885+
if (numBands <= 0) {
886+
throw new IllegalArgumentException("numBands must be > 0");
887+
}
864888
int[] bankIndices = new int[numBands];
865889
for (int i=0; i < numBands; i++) {
866890
bankIndices[i] = i;

src/java.desktop/share/classes/java/awt/image/ComponentSampleModel.java

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,16 @@ public class ComponentSampleModel extends SampleModel
118118
* @param scanlineStride the line stride of the region of image
119119
* data described
120120
* @param bandOffsets the offsets of all bands
121-
* @throws IllegalArgumentException if {@code w} or
122-
* {@code h} is not greater than 0
123-
* @throws IllegalArgumentException if {@code pixelStride}
124-
* is less than 0
125-
* @throws IllegalArgumentException if {@code scanlineStride}
126-
* is less than 0
127-
* @throws IllegalArgumentException if {@code numBands}
128-
* is less than 1
121+
* @throws IllegalArgumentException if {@code w} and {@code h}
122+
* are not both greater than 0
129123
* @throws IllegalArgumentException if the product of {@code w}
130-
* and {@code h} is greater than
131-
* {@code Integer.MAX_VALUE}
124+
* and {@code h} is greater than {@code Integer.MAX_VALUE}
125+
* @throws IllegalArgumentException if {@code pixelStride} is less than 0
126+
* @throws IllegalArgumentException if {@code scanlineStride} is less than 0
127+
* @throws NullPointerException if {@code bandOffsets} is {@code null}
128+
* @throws IllegalArgumentException if {@code bandOffsets.length} is 0
132129
* @throws IllegalArgumentException if {@code dataType} is not
133-
* one of the supported data types
130+
* one of the supported data types for this sample model.
134131
*/
135132
public ComponentSampleModel(int dataType,
136133
int w, int h,
@@ -150,9 +147,6 @@ public ComponentSampleModel(int dataType,
150147
if (scanlineStride < 0) {
151148
throw new IllegalArgumentException("Scanline stride must be >= 0");
152149
}
153-
if (numBands < 1) {
154-
throw new IllegalArgumentException("Must have at least one band.");
155-
}
156150
if ((dataType < DataBuffer.TYPE_BYTE) ||
157151
(dataType > DataBuffer.TYPE_DOUBLE)) {
158152
throw new IllegalArgumentException("Unsupported dataType.");
@@ -181,19 +175,22 @@ public ComponentSampleModel(int dataType,
181175
* data described
182176
* @param bankIndices the bank indices of all bands
183177
* @param bandOffsets the band offsets of all bands
184-
* @throws IllegalArgumentException if {@code w} or
185-
* {@code h} is not greater than 0
186-
* @throws IllegalArgumentException if {@code pixelStride}
187-
* is less than 0
188-
* @throws IllegalArgumentException if {@code scanlineStride}
189-
* is less than 0
178+
* @throws IllegalArgumentException if {@code w} and {@code h}
179+
* are not both greater than 0
180+
* @throws IllegalArgumentException if the product of {@code w}
181+
* and {@code h} is greater than {@code Integer.MAX_VALUE}
182+
* @throws IllegalArgumentException if {@code pixelStride} is less than 0
183+
* @throws IllegalArgumentException if {@code scanlineStride} is less than 0
184+
* @throws NullPointerException if {@code bankIndices} is {@code null}
185+
* @throws NullPointerException if {@code bandOffsets} is {@code null}
186+
* @throws IllegalArgumentException if {@code bandOffsets.length} is 0
190187
* @throws IllegalArgumentException if the length of
191188
* {@code bankIndices} does not equal the length of
192-
* {@code bankOffsets}
189+
* {@code bandOffsets}
193190
* @throws IllegalArgumentException if any of the bank indices
194191
* of {@code bandIndices} is less than 0
195192
* @throws IllegalArgumentException if {@code dataType} is not
196-
* one of the supported data types
193+
* one of the supported data types for this sample model
197194
*/
198195
public ComponentSampleModel(int dataType,
199196
int w, int h,
@@ -207,6 +204,10 @@ public ComponentSampleModel(int dataType,
207204
this.scanlineStride = scanlineStride;
208205
this.bandOffsets = bandOffsets.clone();
209206
this.bankIndices = bankIndices.clone();
207+
if (this.bandOffsets.length != this.bankIndices.length) {
208+
throw new IllegalArgumentException("Length of bandOffsets must "+
209+
"equal length of bankIndices.");
210+
}
210211
if (pixelStride < 0) {
211212
throw new IllegalArgumentException("Pixel stride must be >= 0");
212213
}
@@ -235,10 +236,6 @@ else if (this.bankIndices[i] < 0) {
235236
}
236237
numBanks = maxBank+1;
237238
numBands = this.bandOffsets.length;
238-
if (this.bandOffsets.length != this.bankIndices.length) {
239-
throw new IllegalArgumentException("Length of bandOffsets must "+
240-
"equal length of bankIndices.");
241-
}
242239
verify();
243240
}
244241

0 commit comments

Comments
 (0)