6453640: BandedSampleModel.createCompatibleSampleModel() API docs are wrong

Reviewed-by: azvegint, serb
This commit is contained in:
Phil Race 2025-10-24 22:24:28 +00:00
parent 97e5ac6e72
commit a4eaeb47c9
2 changed files with 105 additions and 8 deletions

View File

@ -141,12 +141,9 @@ public final class BandedSampleModel extends ComponentSampleModel
* @param h the height of the resulting {@code BandedSampleModel}
* @return a new {@code BandedSampleModel} with the specified
* width and height.
* @throws IllegalArgumentException if {@code w} or
* {@code h} equals either
* {@code Integer.MAX_VALUE} or
* {@code Integer.MIN_VALUE}
* @throws IllegalArgumentException if {@code dataType} is not
* one of the supported data types
* @throws IllegalArgumentException if the product of {@code w}
* and {@code h} is greater than {@code Integer.MAX_VALUE}
* or {@code w} or {@code h} is not greater than 0.
*/
public SampleModel createCompatibleSampleModel(int w, int h) {
int[] bandOffs;
@ -172,8 +169,8 @@ public final class BandedSampleModel extends ComponentSampleModel
* of the original BandedSampleModel/DataBuffer combination.
* @throws RasterFormatException if the number of bands is greater than
* the number of banks in this sample model.
* @throws IllegalArgumentException if {@code dataType} is not
* one of the supported data types
* @throws IllegalArgumentException if the number of bands is not greater than 0
* @throws ArrayIndexOutOfBoundsException if any of the bank indices is out of bounds
*/
public SampleModel createSubsetSampleModel(int[] bands) {
if (bands.length > bankIndices.length)

View File

@ -0,0 +1,100 @@
/*
* Copyright (c) 2025, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6453640
* @summary Verify BandedSampleModel.createCompatibleSampleModel
* and createSubsetSampleModel behaviour
* @run main BSMCreateCompatibleSMTest
*/
import java.awt.image.BandedSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.RasterFormatException;
public class BSMCreateCompatibleSMTest {
public static void main(String[] args) {
// These should all be OK
BandedSampleModel bsm = new BandedSampleModel(DataBuffer.TYPE_BYTE, 1, 1, 1);
bsm.createCompatibleSampleModel(20_000, 20_000);
int[] bands = { 0 } ;
bsm.createSubsetSampleModel(bands);
// These should all throw an exception
try {
bsm.createCompatibleSampleModel(-1, 1);
throw new RuntimeException("No exception for illegal w");
} catch (IllegalArgumentException e) {
System.out.println(e);
}
try {
bsm.createCompatibleSampleModel(1, 0);
throw new RuntimeException("No exception for illegal h");
} catch (IllegalArgumentException e) {
System.out.println(e);
}
try {
bsm.createCompatibleSampleModel(-1, -1);
throw new RuntimeException("No exception for illegal w+h");
} catch (IllegalArgumentException e) {
System.out.println(e);
}
try {
bsm.createCompatibleSampleModel(50_000, 50_000);
throw new RuntimeException("No exception for too large dims");
} catch (IllegalArgumentException e) {
System.out.println(e);
}
try {
int[] bands0 = { } ;
bsm.createSubsetSampleModel(bands0);
throw new RuntimeException("No exception for empty bands[]");
} catch (IllegalArgumentException e) {
System.out.println(e);
}
try {
int[] bands1 = { 1 } ;
bsm.createSubsetSampleModel(bands1);
throw new RuntimeException("No exception for out of bounds band");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e);
}
try {
int[] bands2 = { 0, 0 } ;
bsm.createSubsetSampleModel(bands2);
throw new RuntimeException("No exception for too many bands");
} catch (RasterFormatException e) {
System.out.println(e);
}
}
}