harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Denis Kishenko" <dkishe...@gmail.com>
Subject [classlib][awt] Non bug??? BufferedImage constructor throws different exceptions on RI and Harmony
Date Mon, 02 Oct 2006 11:51:27 GMT
Hi all

Constructor of BufferedImage throws different exceptions on RI and
Harmony if width or height is negative. Code to reproduce
     new BufferedImage(8, -7, <type 1-13>)
So we have
1-4 IllegalArgumentException both
5-7 RI - NegativeArraySizeException, Harmony - RasterFormatException
8-9 IllegalArgumentException both
10-11 RI - NegativeArraySizeException, Harmony - IllegalArgumentException
12-13 RI - NegativeArraySizeException, Harmony - RasterFormatException

I think this is non-bug difference because of

5-7 and 12-13: As you see from stack trace both implementations call
Raster.createInterleavedRaster(...)
Spec says
 Throws:
      RasterFormatException - if w or h is less than or equal to zero,
or computing either location.x + w or location.y + h results in
integer overflow
So RI doesn't folow spec while Harmony does.

10-11: For RI the same situation as listed above while Harmony just
has another implementation.

In all cases it's more logical to throw IllegalArgumentException or
RasterFormatException instead of NegativeArraySizeException.

Any comments?


2006/10/2, Denis Kishenko (JIRA) <jira@apache.org>:
> [classlib][awt] BufferedImage constructor throws different exceptions on RI and Harmony
> ----------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1655
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1655
>             Project: Harmony
>          Issue Type: Bug
>          Components: Non-bug differences from RI
>            Reporter: Denis Kishenko
>
>
> Constructor of BufferedImage throws different exceptions on RI and Harmony if width or
height is negative. Type of exception depends on BufferedImage type parameter. There are 13
different types exist. Results are listed below.
>
> 1-4 IllegalArgumentException both
> 5-7 RI - NegativeArraySizeException, Harmony - RasterFormatException
> 8-9 IllegalArgumentException both
> 10-11 RI - NegativeArraySizeException, Harmony - IllegalArgumentException
> 12-13 RI - NegativeArraySizeException, Harmony - RasterFormatException
>
> I think this is non-bug difference because of
>
> 5-7 and 12-13: As you see from stack trace both implementations call Raster.createInterleavedRaster(...)
> Spec says
>  Throws:
>       RasterFormatException - if w or h is less than or equal to zero, or computing either
location.x + w or location.y + h results in integer overflow
> So RI doesn't folow spec while Harmony does.
>
> 10-11: For RI the same situation as listed above while Harmony just has another implementation
and exception order.
>
> In all cases it's more logical to throw IllegalArgumentException or RasterFormatException
instead of NegativeArraySizeException.
>
> =========== Test  ==========
> import java.awt.image.*;
>
> public class Test {
>   public static void main(String[] argv) {
>       for(int i = 1; i < 14; i++) {
>           try {
>               System.err.println(i);
>               new BufferedImage(8, -7, i);
>           } catch (Exception e) {
>               e.printStackTrace();
>           }
>       }
>   }
> }
>
> =========== RI ==============
> 1
> java.lang.IllegalArgumentException: Width (8) and height (-7) cannot be <= 0
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:314)
>    at Test.main(Test.java:8)
> 2
> java.lang.IllegalArgumentException: Width (8) and height (-7) cannot be <= 0
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:323)
>    at Test.main(Test.java:8)
> 3
> java.lang.IllegalArgumentException: Width (8) and height (-7) cannot be <= 0
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:342)
>    at Test.main(Test.java:8)
> 4
> java.lang.IllegalArgumentException: Width (8) and height (-7) cannot be <= 0
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:354)
>    at Test.main(Test.java:8)
> 5
> java.lang.NegativeArraySizeException: Negative size-168
>    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:367)
>    at Test.main(Test.java:8)
> 6
> java.lang.NegativeArraySizeException: Negative size-224
>    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:382)
>    at Test.main(Test.java:8)
> 7
> java.lang.NegativeArraySizeException: Negative size-224
>    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:397)
>    at Test.main(Test.java:8)
> 8
> java.lang.IllegalArgumentException: Width (8) and height (-7) cannot be <= 0
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:474)
>    at Test.main(Test.java:8)
> 9
> java.lang.IllegalArgumentException: Width (8) and height (-7) cannot be <= 0
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:486)
>    at Test.main(Test.java:8)
> 10
> java.lang.NegativeArraySizeException: Negative size-56
>    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:194)
>    at java.awt.image.ComponentColorModel.createCompatibleWritableRaster(ComponentColorModel.java:2808)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:411)
>    at Test.main(Test.java:8)
> 11
> java.lang.NegativeArraySizeException: Negative size-56
>    at java.awt.image.DataBufferUShort.<init>(DataBufferUShort.java:43)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:257)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:194)
>    at java.awt.image.ComponentColorModel.createCompatibleWritableRaster(ComponentColorModel.java:2808)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:423)
>    at Test.main(Test.java:8)
> 12
> java.lang.NegativeArraySizeException: Negative size-7
>    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
>    at java.awt.image.Raster.createPackedRaster(Raster.java:566)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:433)
>    at Test.main(Test.java:8)
> 13
> java.lang.NegativeArraySizeException: Negative size-56
>    at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:194)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:462)
>    at Test.main(Test.java:8)
>
>
> ============ Harmony ================
> 1
> java.lang.IllegalArgumentException: w or h is less than or equal to zero
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:518)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:188)
> 2
> java.lang.IllegalArgumentException: w or h is less than or equal to zero
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:518)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:193)
> 3
> java.lang.IllegalArgumentException: w or h is less than or equal to zero
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:518)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:207)
> 4
> java.lang.IllegalArgumentException: w or h is less than or equal to zero
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:518)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:216)
> 5
> java.awt.image.RasterFormatException: w or h is less than or equal to zero
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:242)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:231)
> 6
> java.awt.image.RasterFormatException: w or h is less than or equal to zero
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:242)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:247)
> 7
> java.awt.image.RasterFormatException: w or h is less than or equal to zero
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:242)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:262)
> 8
> java.lang.IllegalArgumentException: w or h is less than or equal to zero
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:518)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:277)
> 9
> java.lang.IllegalArgumentException: w or h is less than or equal to zero
>    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:518)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:291)
> 10
> java.lang.IllegalArgumentException: Width or Height is not greater than 0
>    at java.awt.image.SampleModel.<init>(SampleModel.java:34)
>    at java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:79)
>    at java.awt.image.PixelInterleavedSampleModel.<init>(PixelInterleavedSampleModel.java:27)
>    at java.awt.image.ComponentColorModel.createCompatibleSampleModel(ComponentColorModel.java:964)
>    at java.awt.image.ComponentColorModel.createCompatibleWritableRaster(ComponentColorModel.java:935)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:304)
> 11
> java.lang.IllegalArgumentException: Width or Height is not greater than 0
>    at java.awt.image.SampleModel.<init>(SampleModel.java:34)
>    at java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:79)
>    at java.awt.image.PixelInterleavedSampleModel.<init>(PixelInterleavedSampleModel.java:27)
>    at java.awt.image.ComponentColorModel.createCompatibleSampleModel(ComponentColorModel.java:964)
>    at java.awt.image.ComponentColorModel.createCompatibleWritableRaster(ComponentColorModel.java:935)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:317)
> 12
> java.awt.image.RasterFormatException: w or h is less than or equal to zero
>    at java.awt.image.Raster.createPackedRaster(Raster.java:410)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:327)
> 13
> java.awt.image.RasterFormatException: w or h is less than or equal to zero
>    at java.awt.image.Raster.createInterleavedRaster(Raster.java:292)
>    at java.awt.image.BufferedImage.<init>(BufferedImage.java:350)
>
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>


-- 
Denis M. Kishenko
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message