Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8255800: Raster creation methods need some specification clean up #3223

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 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
@@ -78,8 +78,13 @@
* @param h The height (in pixels) of the region of image
* data described.
* @param numBands The number of bands for the image data.
* @throws IllegalArgumentException if {@code w} and {@code h}
* are not both greater than 0
* @throws IllegalArgumentException if the product of {@code w}
* and {@code h} is greater than {@code Integer.MAX_VALUE}
* @throws IllegalArgumentException if {@code numBands} is not > 0
* @throws IllegalArgumentException if {@code dataType} is not
* one of the supported data types
* one of the supported data types for this sample model.
*/
public BandedSampleModel(int dataType, int w, int h, int numBands) {
super(dataType, w, h, 1, w,
@@ -100,8 +105,21 @@ public BandedSampleModel(int dataType, int w, int h, int numBands) {
* @param scanlineStride The line stride of the of the image data.
* @param bankIndices The bank index for each band.
* @param bandOffsets The band offset for each band.
* @throws IllegalArgumentException if {@code w} and {@code h}
* are not both greater than 0
* @throws IllegalArgumentException if the product of {@code w}
* and {@code h} is greater than {@code Integer.MAX_VALUE}
* @throws IllegalArgumentException if {@code scanlineStride} is less than 0
* @throws NullPointerException if {@code bankIndices} is {@code null}
* @throws NullPointerException if {@code bandOffsets} is {@code null}
* @throws IllegalArgumentException if {@code bandOffsets.length} is 0
* @throws IllegalArgumentException if the length of
* {@code bankIndices} does not equal the length of
* {@code bandOffsets}
* @throws IllegalArgumentException if any of the bank indices
* of {@code bandIndices} is less than 0
* @throws IllegalArgumentException if {@code dataType} is not
* one of the supported data types
* one of the supported data types for this sample model
*/
public BandedSampleModel(int dataType,
int w, int h,
@@ -853,6 +871,9 @@ public void setSamples(int x, int y, int w, int h, int b,
}

private static int[] createOffsetArray(int numBands) {
if (numBands <= 0) {
throw new IllegalArgumentException("numBands must be > 0");
}
int[] bandOffsets = new int[numBands];
for (int i=0; i < numBands; i++) {
bandOffsets[i] = 0;
@@ -861,6 +882,9 @@ public void setSamples(int x, int y, int w, int h, int b,
}

private static int[] createIndicesArray(int numBands) {
if (numBands <= 0) {
throw new IllegalArgumentException("numBands must be > 0");
}
int[] bankIndices = new int[numBands];
for (int i=0; i < numBands; i++) {
bankIndices[i] = i;
@@ -118,19 +118,16 @@
* @param scanlineStride the line stride of the region of image
* data described
* @param bandOffsets the offsets of all bands
* @throws IllegalArgumentException if {@code w} or
* {@code h} is not greater than 0
* @throws IllegalArgumentException if {@code pixelStride}
* is less than 0
* @throws IllegalArgumentException if {@code scanlineStride}
* is less than 0
* @throws IllegalArgumentException if {@code numBands}
* is less than 1
* @throws IllegalArgumentException if {@code w} and {@code h}
* are not both greater than 0
* @throws IllegalArgumentException if the product of {@code w}
* and {@code h} is greater than
* {@code Integer.MAX_VALUE}
* and {@code h} is greater than {@code Integer.MAX_VALUE}
* @throws IllegalArgumentException if {@code pixelStride} is less than 0
* @throws IllegalArgumentException if {@code scanlineStride} is less than 0
* @throws NullPointerException if {@code bandOffsets} is {@code null}

This comment has been minimized.

Loading
@mrserb

mrserb Mar 26, 2021
Member

I like the NPE here, but probably it makes sense to use the same exception for all errors? "IllegalArgumentException "

This comment has been minimized.

Loading
@prrace

prrace Mar 26, 2021
Author Contributor

Meaning even though you like the NPE you would change it to IAE like the rest ?

This comment has been minimized.

Loading
@mrserb

mrserb Mar 31, 2021
Member

Yes and no, I just wanted to highlight this place, since somebody may prefer IAE here.

This comment has been minimized.

Loading
@prrace

prrace Mar 31, 2021
Author Contributor

Well IAE was my initial thought but I decided to minimize the behavioral changes.

* @throws IllegalArgumentException if {@code bandOffsets.length} is 0
* @throws IllegalArgumentException if {@code dataType} is not
* one of the supported data types
* one of the supported data types for this sample model.
*/
public ComponentSampleModel(int dataType,
int w, int h,
@@ -150,9 +147,6 @@ public ComponentSampleModel(int dataType,
if (scanlineStride < 0) {
throw new IllegalArgumentException("Scanline stride must be >= 0");
}
if (numBands < 1) {
throw new IllegalArgumentException("Must have at least one band.");
}
if ((dataType < DataBuffer.TYPE_BYTE) ||
(dataType > DataBuffer.TYPE_DOUBLE)) {
throw new IllegalArgumentException("Unsupported dataType.");
@@ -181,19 +175,22 @@ public ComponentSampleModel(int dataType,
* data described
* @param bankIndices the bank indices of all bands
* @param bandOffsets the band offsets of all bands
* @throws IllegalArgumentException if {@code w} or
* {@code h} is not greater than 0
* @throws IllegalArgumentException if {@code pixelStride}
* is less than 0
* @throws IllegalArgumentException if {@code scanlineStride}
* is less than 0
* @throws IllegalArgumentException if {@code w} and {@code h}
* are not both greater than 0
* @throws IllegalArgumentException if the product of {@code w}
* and {@code h} is greater than {@code Integer.MAX_VALUE}
* @throws IllegalArgumentException if {@code pixelStride} is less than 0
* @throws IllegalArgumentException if {@code scanlineStride} is less than 0
* @throws NullPointerException if {@code bankIndices} is {@code null}
* @throws NullPointerException if {@code bandOffsets} is {@code null}
* @throws IllegalArgumentException if {@code bandOffsets.length} is 0
* @throws IllegalArgumentException if the length of
* {@code bankIndices} does not equal the length of
* {@code bankOffsets}
* {@code bandOffsets}
* @throws IllegalArgumentException if any of the bank indices
* of {@code bandIndices} is less than 0
* @throws IllegalArgumentException if {@code dataType} is not
* one of the supported data types
* one of the supported data types for this sample model
*/
public ComponentSampleModel(int dataType,
int w, int h,
@@ -207,6 +204,10 @@ public ComponentSampleModel(int dataType,
this.scanlineStride = scanlineStride;
this.bandOffsets = bandOffsets.clone();
this.bankIndices = bankIndices.clone();
if (this.bandOffsets.length != this.bankIndices.length) {
throw new IllegalArgumentException("Length of bandOffsets must "+
"equal length of bankIndices.");
}
if (pixelStride < 0) {
throw new IllegalArgumentException("Pixel stride must be >= 0");
}
@@ -235,10 +236,6 @@ else if (this.bankIndices[i] < 0) {
}
numBanks = maxBank+1;
numBands = this.bandOffsets.length;
if (this.bandOffsets.length != this.bankIndices.length) {
throw new IllegalArgumentException("Length of bandOffsets must "+
"equal length of bankIndices.");
}
verify();
}

Loading