harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r501076 - in /harmony/enhanced/classlib/trunk/modules/awt/src: main/java/common/java/awt/image/MultiPixelPackedSampleModel.java test/api/java/common/java/awt/image/MultiPixelPackedSampleModelTest.java
Date Mon, 29 Jan 2007 15:11:23 GMT
Author: ayza
Date: Mon Jan 29 07:11:18 2007
New Revision: 501076

URL: http://svn.apache.org/viewvc?view=rev&rev=501076
Log:
Applying the patch from HARMONY-2779 ([classlib][awt] Compatibility: java.awt.image.MultiPixelPackedSampleModel.setDataElements(int
,int,Object ,DataBuffer) throws unspecified NPE while Ri throws ArrayIndexOutOfBoundsException)

Modified:
    harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/MultiPixelPackedSampleModel.java
    harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/MultiPixelPackedSampleModelTest.java

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/MultiPixelPackedSampleModel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/MultiPixelPackedSampleModel.java?view=diff&rev=501076&r1=501075&r2=501076
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/MultiPixelPackedSampleModel.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/main/java/common/java/awt/image/MultiPixelPackedSampleModel.java
Mon Jan 29 07:11:18 2007
@@ -126,17 +126,28 @@
             // awt.63=Coordinates are not in bounds
             throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.63")); //$NON-NLS-1$
         }
+        
+        int bitnum = dataBitOffset + x * pixelBitStride;
+        int idx = y * scanlineStride + bitnum / dataElementSize;
+        int elem = data.getElem(idx);
+        int shift = dataElementSize - (bitnum & (dataElementSize - 1)) -
+                pixelBitStride;
+        int mask = ~(bitMask << shift);
+        elem &= mask;
+        
         switch (getTransferType()) {
         case DataBuffer.TYPE_BYTE:
-            setSample(x, y, 0, ((byte[]) obj)[0] & 0xff, data);
+            elem |= (((byte[]) obj)[0] & 0xff & bitMask) << shift;
             break;
         case DataBuffer.TYPE_USHORT:
-            setSample(x, y, 0, ((short[]) obj)[0] & 0xffff, data);
+            elem |= (((short[]) obj)[0] & 0xffff & bitMask) << shift;
             break;
         case DataBuffer.TYPE_INT:
-            setSample(x, y, 0, ((int[]) obj)[0], data);
+            elem |= (((int[]) obj)[0] & bitMask) << shift;
             break;
         }
+        
+        data.setElem(idx, elem);
     }
 
     @Override

Modified: harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/MultiPixelPackedSampleModelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/MultiPixelPackedSampleModelTest.java?view=diff&rev=501076&r1=501075&r2=501076
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/MultiPixelPackedSampleModelTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/awt/src/test/api/java/common/java/awt/image/MultiPixelPackedSampleModelTest.java
Mon Jan 29 07:11:18 2007
@@ -31,6 +31,8 @@
 import java.util.Arrays;
 import java.util.Random;
 
+import javax.swing.JSplitPane;
+
 import junit.framework.TestCase;
 
 public class MultiPixelPackedSampleModelTest extends TestCase {
@@ -1755,6 +1757,25 @@
 
             }
         }
+        
+        // Regression for HARMONY-2779
+        try {
+            new MultiPixelPackedSampleModel(0, 52, 4, 8).setDataElements(6, 2,
+                    (Object) null, new DataBufferFloat(4, 1));
+            fail("ArrayIndexOutOfBoundsException was not thrown"); //$NON-NLS-1$
+        } catch (ArrayIndexOutOfBoundsException ex) {
+            // expected
+        }
+        
+        // Regression for HARMONY-2779
+        try {
+            new MultiPixelPackedSampleModel(0, 14907, 18936, 2)
+                    .setDataElements(14, 14, new JSplitPane(),
+                            (DataBuffer) null);
+            fail("NullPointerException was not thrown"); //$NON-NLS-1$
+        } catch (NullPointerException  ex) {
+            // expected
+        }
     }
 
     public final void testSetPixel() {
@@ -2731,4 +2752,6 @@
             int bank) {
         return createPixelsFromIntData(x, y, width, height);
     }
+    
+    
 }



Mime
View raw message