Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4434870

javax.imageio.ImageWriteParam.setTiling() does not throw expected exception

XMLWordPrintable

    • beta2
    • generic
    • generic



      Name: vrR10176 Date: 04/06/2001



      Api spec (jdk1.4.0beta-b58) says about method
      javax.imageio.ImageWriteParam.setTiling():
      "public void setTiling(int tileWidth, int tileHeight,
                             int tileGridXOffset, int tileGridYOffset)
        Specifies that the image should be tiled in the output stream. The tileWidth
      and tileHeight parameters specify the width and height of the tiles in the file.
      If the tile width or height is greater than the width or height of the image,
      the image is not tiled in that dimension.
      ...skip...
      Throws:
      ...skip...
        IllegalArgumentException - if the tile size is not within one of the allowable
      ranges returned by getPreferredTileSizes."

      and about method javax.imageio.ImageWriteParam.getPreferredTileSizes():
      "public Dimension[] getPreferredTileSizes()
        Returns an array of Dimensions indicating the legal size ranges for tiles as
      they will be encoded in the output file or stream. The returned array is a copy.
        The information is returned as a set of pairs; the first element of a pair
      contains an (inclusive) minimum width and height, and the second element contains
      an (inclusive) maximum width and height. Together, each pair defines a valid range
      of sizes. To specify a fixed size, use the same width and height for both elements.
      To specify an arbitrary range, a value of null is used in place of an actual array
      of Dimensions. ..."

      Therefore if tileWidth or tileHeight is greater than maximum width or height respectively
      then setTiling() should throw IllegalArgumentException, but the method does not work
      as expected.

      To reproduce the issue execute following test.
      ------------ myImageWriteParam.java ------------------------
      import javax.imageio.ImageWriteParam;
      import java.awt.Dimension;

      public class myImageWriteParam extends ImageWriteParam {

      public myImageWriteParam() {
      super(null);
      super.canWriteTiles = true;
      super.preferredTileSizes = new Dimension[]{new Dimension(1,2),new Dimension(5,6)};
      }

      public static void main(String[] argv) {
      myImageWriteParam myimagewriteparam = new myImageWriteParam();
      try{
      Dimension[] dimensions = myimagewriteparam.getPreferredTileSizes();
      System.out.println("min width: " + dimensions[0].width + " min height: " + dimensions[0].height);
      System.out.println("max width: " + dimensions[1].width + " max height: " + dimensions[1].height);
      myimagewriteparam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
      myimagewriteparam.setTiling(100,100,0,0);
      System.out.println("Test failed. IllegalArgumentException was expected");
      } catch (IllegalArgumentException e) {
      System.out.println("Test passed");
      }
      }
      }
      ------------ Logs ------------------------------------------
      $ javac myImageWriteParam.java

      $ java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b58)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b58, mixed mode)

      $ java myImageWriteParam
      min width: 1 min height: 2
      max width: 5 max height: 6
      Test failed. IllegalArgumentException was expected
      -----------------------------------------------

      ======================================================================

            dricesunw Daniel Rice (Inactive)
            rslasunw Rsla Rsla (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: