You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2007/01/12 22:08:06 UTC
svn commit: r495741 - in /harmony/enhanced/classlib/trunk/modules/awt/src:
main/java/common/java/awt/image/ComponentSampleModel.java
test/api/java/common/java/awt/image/ComponentSampleModelTest.java
Author: hindessm
Date: Fri Jan 12 13:08:05 2007
New Revision: 495741
URL: http://svn.apache.org/viewvc?view=rev&rev=495741
Log:
Applied patches from "[#HARMONY-2190] [classlib][awt] Harmony
ComponentSampleModel.setDataElements(int x, int y, Object obj, DataBuffer
data) doesn't throw ArrayIndexOutOfBoundsException when x or y have
wrong value, but RI implementation does".
Modified:
harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ComponentSampleModel.java
harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ComponentSampleModelTest.java
Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ComponentSampleModel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ComponentSampleModel.java?view=diff&rev=495741&r1=495740&r2=495741
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ComponentSampleModel.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/ComponentSampleModel.java Fri Jan 12 13:08:05 2007
@@ -106,6 +106,10 @@
@Override
public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
+ // awt.63=Coordinates are not in bounds
+ throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
+ }
switch (dataType) {
case DataBuffer.TYPE_BYTE:
byte bdata[];
@@ -189,6 +193,10 @@
@Override
public void setDataElements(int x, int y, Object obj, DataBuffer data) {
+ if (x < 0 || y < 0 || x >= this.width || y >= this.height) {
+ // awt.63=Coordinates are not in bounds
+ throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
+ }
switch (dataType) {
case DataBuffer.TYPE_BYTE:
byte barr[] = (byte[]) obj;
Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ComponentSampleModelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ComponentSampleModelTest.java?view=diff&rev=495741&r1=495740&r2=495741
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ComponentSampleModelTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/ComponentSampleModelTest.java Fri Jan 12 13:08:05 2007
@@ -16,12 +16,55 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package java.awt.image;
import junit.framework.TestCase;
public class ComponentSampleModelTest extends TestCase {
-
+
+ public ComponentSampleModelTest(String name) {
+ super(name);
+ }
+
+ public final void testSetDataElements(){
+ // Checking ArrayIndexOutOfBoundsException when passes wrong x or y
+ int[] offsets = new int[4];
+ ComponentSampleModel csm = new
+ ComponentSampleModel(DataBuffer.TYPE_USHORT,238,4,7,14,offsets);
+ ComponentSampleModel obj = new
+ ComponentSampleModel(DataBuffer.TYPE_USHORT,1,2,3,15, offsets);
+
+ DataBufferFloat db = new DataBufferFloat(4);
+ try{
+ csm.setDataElements(-1399, 2, obj, db);
+ fail("Expected ArrayIndexOutOfBoundsException didn't throw");
+ }catch (ClassCastException e) {
+ fail("Unexpected ClassCastException was thrown");
+ }catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue(true);
+ }
+ }
+
+ public final void testGetDataElements(){
+ // Checking ArrayIndexOutOfBoundsException when passes wrong x or y
+ int[] offsets = new int[4];
+ ComponentSampleModel csm = new
+ ComponentSampleModel(DataBuffer.TYPE_USHORT,238,4,7,14,offsets);
+ ComponentSampleModel obj = new
+ ComponentSampleModel(DataBuffer.TYPE_USHORT,1,2,3,15, offsets);
+
+ DataBufferFloat db = new DataBufferFloat(4);
+ try{
+ csm.getDataElements(-1399, 2, obj, db);
+ fail("Expected ArrayIndexOutOfBoundsException didn't throw");
+ }catch (ClassCastException e) {
+ fail("Unexpected ClassCastException was thrown");
+ }catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue(true);
+ }
+ }
+
public void testGetPixelsMaxValue() throws Exception {
ComponentSampleModel csm = new ComponentSampleModel(0, 10, 10, 1, 10, new int[]{0});
DataBufferInt dbi = new DataBufferInt(100);
@@ -33,4 +76,5 @@
// expected
}
}
+
}