[OpenJDK 2D-Dev] RFR: 8166038 BufferedImage methods getTileGridXOffset() and getTileGridYOffset() return a non 0 value for sub images

Martin Desruisseaux martin.desruisseaux at geomatys.com
Thu Jun 25 15:03:41 UTC 2020


Following up on JDK-8166038 [1], in case it may help to justify the 
proposed fix, attached is another test case demonstrating the bug. 
Attempt to draw a BufferedImage subimage with Graphics2D causes an 
exception to be thrown if we hide the fact that the image is a 
BufferedImage instance, for preventing SunGraphics2D to use its special 
cases for BufferedImage. Stack trace is:

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: BufferedImages only have one tile with index 0,0
    	at java.desktop/java.awt.image.BufferedImage.getTile(BufferedImage.java:1401)
    	at SubimageDrawingTest$Wrapper.getTile(SubimageDrawingTest.java:136)
    	at java.desktop/sun.java2d.SunGraphics2D.drawTranslatedRenderedImage(SunGraphics2D.java:2821)
    	at java.desktop/sun.java2d.SunGraphics2D.drawRenderedImage(SunGraphics2D.java:2708)
    	at SubimageDrawingTest.main(SubimageDrawingTest.java:31)

Replacing getTileGridXOffset() and getTileGridYOffset() return values by 
0 (as expected and as requested by method contract) fix the bug.

This bug happens with any code that try to handle RenderedImage tiles in 
a generic way, without making special case for BufferedImage (we have 
encounter this issue today in Apache Spatial Information System).



[1] https://bugs.openjdk.java.net/browse/JDK-8166038

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/2d-dev/attachments/20200625/05bb030f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SubimageDrawingTest.java
Type: text/x-java
Size: 4040 bytes
Desc: not available
URL: <https://mail.openjdk.java.net/pipermail/2d-dev/attachments/20200625/05bb030f/SubimageDrawingTest.java>

More information about the 2d-dev mailing list