changeset 1270:7eb62ef86e4f

Fix RT-21831: Specify ranges for WritableImage constructor parameters.
author flar <James.Graham@oracle.com>
date Tue, 05 Jun 2012 18:58:25 -0700
parents 0498a5aa3193
children 188ee39990fe
files javafx-ui-common/src/javafx/scene/image/Image.java javafx-ui-common/src/javafx/scene/image/WritableImage.java
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/image/Image.java	Tue Jun 05 08:42:25 2012 -0700
+++ b/javafx-ui-common/src/javafx/scene/image/Image.java	Tue Jun 05 18:58:25 2012 -0700
@@ -647,18 +647,18 @@
     }
 
     /**
-     * Construct a new empty {@code Image} with the specified dimensions
-     * filled with transparent pixels to be used with the
-     * {@link #setArgb(int, int, int) setArgb()}
-     * and
-     * {@link #setColor(int, int, javafx.scene.paint.Color) setColor()}
-     * methods to create a completely custom image.
+     * Package private internal constructor used only by {@link WritableImage}.
+     * The dimensions must both be positive numbers <code>(&gt;&nbsp;0)</code>.
      * 
      * @param width the width of the empty image
      * @param height the height of the empty image
+     * @throws IllegalArgumentException if either dimension is negative or zero.
      */
     Image(int width, int height) {
         this(null, null, width, height, false, false, false);
+        if (width <= 0 || height <= 0) {
+            throw new IllegalArgumentException("Image dimensions must be positive (w,h > 0)");
+        }
         initialize(Toolkit.getToolkit().createPlatformImage(width, height));
     }
 
--- a/javafx-ui-common/src/javafx/scene/image/WritableImage.java	Tue Jun 05 08:42:25 2012 -0700
+++ b/javafx-ui-common/src/javafx/scene/image/WritableImage.java	Tue Jun 05 18:58:25 2012 -0700
@@ -62,9 +62,11 @@
      * Images constructed this way will always be readable and writable
      * so the corresponding getPixelReader() and getPixelWriter() will
      * always return valid objects.
+     * The dimensions must both be positive numbers <code>(&gt;&nbsp;0)</code>.
      * 
      * @param width the desired width of the writable image
      * @param height the desired height of the desired image
+     * @throws IllegalArgumentException if either dimension is negative or zero.
      */
     public WritableImage(int width, int height) {
         super(width, height);
@@ -81,6 +83,7 @@
      * Images constructed this way will always be readable and writable
      * so the corresponding getPixelReader() and getPixelWriter() will
      * always return valid objects.
+     * The dimensions must both be positive numbers <code>(&gt;&nbsp;0)</code>.
      * 
      * @param width the desired width of the writable image and the
      *        width of the region to be read from the {@code reader}
@@ -88,6 +91,7 @@
      *        width of the region to be read from the {@code reader}
      * @throws ArrayIndexOutOfBoundsException if the {@code reader} does
      *         not access a surface of at least the requested dimensions
+     * @throws IllegalArgumentException if either dimension is negative or zero.
      */
     public WritableImage(PixelReader reader, int width, int height) {
         super(width, height);
@@ -105,6 +109,7 @@
      * Images constructed this way will always be readable and writable
      * so the corresponding getPixelReader() and getPixelWriter() will
      * always return valid objects.
+     * The dimensions must both be positive numbers <code>(&gt;&nbsp;0)</code>.
      * 
      * @param x the X coordinate of the upper left corner of the region to
      *        read from the {@code reader}
@@ -116,6 +121,7 @@
      *        width of the region to be read from the {@code reader}
      * @throws ArrayIndexOutOfBoundsException if the {@code reader} does
      *         not access a surface containing at least the indicated region
+     * @throws IllegalArgumentException if either dimension is negative or zero.
      */
     public WritableImage(PixelReader reader,
                          int x, int y, int width, int height)