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

setSourceRenderSize() works incorrectly

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta2
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description



      Name: vrR10176 Date: 06/05/2001



      Api spec (jdk1.4.0beta-b66) says about the method
      javax.imageio.ImageReadParam.setSourceRenderSize():
      "public void setSourceRenderSize(Dimension size)
                               throws UnsupportedOperationException
        If the image is able to be rendered at an arbitrary size, sets
      the source width and height to the supplied values.
      ...
        To remove the render size setting, pass in a value of null for size.
      ...
      Throws:
        IllegalArgumentException - if either the width or the height is negative or 0.
      ..."

      There are two issues in implementation of this method:

      1. If canSetSourceRenderSize is set to true and null is passed as argument
      to the method, it must remove the render size setting without any exception.
      But the method throws NullPointerException.

      2. If canSetSourceRenderSize is set to true and either the width or the height
      is negative or 0, the method does not throw expected IllegalArgumentException.

      This bug causes failure of new JCK test:
      api/javax_imageio/ImageReadParam/index.html#setSourceRenderSize

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

      public class myImageReadParam extends ImageReadParam {

          public myImageReadParam(){
              super.canSetSourceRenderSize = true;
          }

          public static void main(String[] argv) {

              myImageReadParam imageReadParam = new myImageReadParam();

              // test case 1
              try {
                  imageReadParam.setSourceRenderSize(null); // null argument
                  System.out.println("Test case 1 passed");
              } catch (Throwable e) {
                  System.out.println("Test case 1 failed with " + e);
              }

              // test case 2
              try {
                  imageReadParam.setSourceRenderSize(new Dimension( 0, 4)); // width is 0
                  imageReadParam.setSourceRenderSize(new Dimension( 4, 0)); // height is 0
                  imageReadParam.setSourceRenderSize(new Dimension(-4, 4)); // width is negative
                  imageReadParam.setSourceRenderSize(new Dimension( 4,-4)); // height is negative
                  System.out.println("Test case 2 failed. IllegalArgumentException was expected");
              } catch (IllegalArgumentException e) {
                  System.out.println("Test case 2 passed");
              } catch (Throwable e) {
                  System.out.println("est case 2 failed with unexpected exception: " + e);
              }

          }

      }
      ------------ Logs ------------------------------------------
      $ java -version
      java version "1.4.0-beta_refresh"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b66)
      Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b66, mixed mode)

      $ javac myImageReadParam.java

      $ java myImageReadParam
      Test case 1 failed with java.lang.NullPointerException
      Test case 2 failed. IllegalArgumentException was expected
      -----------------------------------------------

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: