harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r517767 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/image/Raster.java main/java/common/org/apache/harmony/awt/internal/nls/messages.properties test/api/java/common/java/awt/image/RasterTest.java
Date Tue, 13 Mar 2007 16:50:00 GMT
Author: apetrenko
Date: Tue Mar 13 09:49:59 2007
New Revision: 517767

URL: http://svn.apache.org/viewvc?view=rev&rev=517767
Log:
Patch for HARMONY-2884 "[classlib][awt] Compatibility: java.awt.image.Raster.createPackedRaster()
throws RasterFormatException on RI while it doesn't on Harmony"

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/RasterTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java?view=diff&rev=517767&r1=517766&r2=517767
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/Raster.java
Tue Mar 13 09:49:59 2007
@@ -601,6 +601,19 @@
             // awt.284=Overflow Y coordinate of Raster
             throw new RasterFormatException(Messages.getString("awt.284")); //$NON-NLS-1$
         }
+        
+        if (sampleModel instanceof ComponentSampleModel) {
+            validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
+                    ((ComponentSampleModel) sampleModel).getScanlineStride());
+        } else if (sampleModel instanceof MultiPixelPackedSampleModel) {
+            validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
+                    ((MultiPixelPackedSampleModel) sampleModel)
+                            .getScanlineStride());
+        } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
+            validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
+                    ((SinglePixelPackedSampleModel) sampleModel)
+                            .getScanlineStride());
+        }
 
         this.sampleModel = sampleModel;
         this.dataBuffer = dataBuffer;
@@ -839,6 +852,13 @@
         return width;
     }
 
+    private static void validateDataBuffer(final DataBuffer dataBuffer, final int w,
+            final int h, final int scanlineStride) {
+        if (dataBuffer.getSize() < (scanlineStride * (h - 1) + w - 1)) {
+            // awt.298=dataBuffer is too small
+            throw new RasterFormatException(Messages.getString("awt.298")); //$NON-NLS-1$
+        }
+    }
 }
 
 

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties?view=diff&rev=517767&r1=517766&r2=517767
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/org/apache/harmony/awt/internal/nls/messages.properties
Tue Mar 13 09:49:59 2007
@@ -486,6 +486,7 @@
 awt.295=data is null
 awt.296=can't allocate memory on video card to create new display list
 awt.297=Invalid keyLocation
+awt.298=dataBuffer is too small
 
 awt.err.00=file dialog {0} error!
 awt.err.01=error: {0}

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/RasterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/RasterTest.java?view=diff&rev=517767&r1=517766&r2=517767
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/RasterTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/RasterTest.java
Tue Mar 13 09:49:59 2007
@@ -45,14 +45,32 @@
         }
     }
     
-    // Regression test for harmony-2717
-    public void test_createPackedRaster() throws RasterFormatException {
+    public void testCreatePackedRaster() throws RasterFormatException {
+        // Regression test for harmony-2717
         try {
             Raster.createPackedRaster(null, -32, Integer.MAX_VALUE, 35, new int[] {}, null);
-            fail("Exception expected");
+            fail("Exception expected"); //$NON-NLS-1$
         } catch (NullPointerException expectedException) {
             // Expected
         }
+        
+        // Regression for HARMONY-2884
+        try {
+            Raster.createPackedRaster(new DataBufferInt(1), 7, 9, 214,
+                    new int[] { 0, 0, 0 }, new Point(10292, 0));
+            fail("RasterFormatException expected!"); //$NON-NLS-1$
+        } catch (RasterFormatException e) {
+            // expected
+        }
+        
+        try {
+            Raster.createRaster(new SinglePixelPackedSampleModel(1, 10, 12, 0,
+                    new int[431]), new DataBufferUShort(new short[5], 3),
+                    new Point());
+            fail("RasterFormatException expected!"); //$NON-NLS-1$
+        } catch (RasterFormatException e) {
+            // expected
+        }
     }
     
     // Regression test for harmony-2885
@@ -90,7 +108,7 @@
         // Regression test for HARMONY-2875
         try {
             Raster.createRaster(new BandedSampleModel(1, 2, 3, 4),
-                    new DataBufferByte(new byte[191], 0),
+                    new DataBufferByte(new byte[191], 5),
                     new Point(new Point(28, 43))).getPixels(6,
                     Integer.MAX_VALUE, 1, 0, new int[] {});
             fail("ArrayIndexOutOfBoundsException should be thrown"); //$NON-NLS-1$



Mime
View raw message