6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode
authorminqi
Mon, 08 Mar 2010 11:35:30 -0800
changeset 4955 e99245ecb5b2
parent 4954 1f09a5b49505
child 4956 81fdf9d1cfea
child 5140 9b1fde936a71
6918065: Crash in Java2D blit loop (IntArgbToIntArgbPreSrcOverMaskBlit) in 64bit mode Reviewed-by: igor, bae
jdk/src/share/classes/java/awt/AlphaComposite.java
jdk/test/java/awt/AlphaComposite/TestAlphaCompositeForNaN.java
--- a/jdk/src/share/classes/java/awt/AlphaComposite.java	Wed Mar 03 15:50:33 2010 +0100
+++ b/jdk/src/share/classes/java/awt/AlphaComposite.java	Mon Mar 08 11:35:30 2010 -0800
@@ -614,14 +614,15 @@
     }
 
     private AlphaComposite(int rule, float alpha) {
-        if (alpha < 0.0f || alpha > 1.0f) {
-            throw new IllegalArgumentException("alpha value out of range");
-        }
         if (rule < MIN_RULE || rule > MAX_RULE) {
             throw new IllegalArgumentException("unknown composite rule");
         }
-        this.rule = rule;
-        this.extraAlpha = alpha;
+        if (alpha >= 0.0f && alpha <= 1.0f) {
+            this.rule = rule;
+            this.extraAlpha = alpha;
+        } else {
+            throw new IllegalArgumentException("alpha value out of range");
+        }
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/AlphaComposite/TestAlphaCompositeForNaN.java	Mon Mar 08 11:35:30 2010 -0800
@@ -0,0 +1,22 @@
+/*
+ * @test
+ * @bug 6918065
+ * @summary Test for passing NaN as alpha
+ *          should throw IllegalArgumentException
+ */
+
+import java.awt.*;
+
+public class TestAlphaCompositeForNaN {
+  public static void main(String[] args) {
+    try {
+      AlphaComposite a = AlphaComposite.getInstance(AlphaComposite.DST, Float.NaN);
+      System.out.println("Failed");
+      throw new RuntimeException(a + " failed to throw IllegalArgumentException for alpha = " + Float.NaN);
+    }
+    catch (IllegalArgumentException ie) {
+      System.out.println("Passed");
+      System.out.println("Caught " + ie);
+    }
+  }
+}