6853916: java.awt.Window.setBackground(null) throws NullPointerException
authoranthony
Tue, 07 Jul 2009 17:05:50 +0400
changeset 3231 10acb97474ff
parent 3091 a0ed74718a4b
child 3232 aacdc74b37d2
6853916: java.awt.Window.setBackground(null) throws NullPointerException Summary: Window.setBackground() should check for null. Reviewed-by: art, dcherepanov
jdk/src/share/classes/java/awt/Window.java
jdk/test/java/awt/Window/SetBackgroundNPE/SetBackgroundNPE.java
--- a/jdk/src/share/classes/java/awt/Window.java	Tue Jun 30 02:48:38 2009 -0700
+++ b/jdk/src/share/classes/java/awt/Window.java	Tue Jul 07 17:05:50 2009 +0400
@@ -3597,7 +3597,7 @@
             return;
         }
         int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
-        int alpha = bgColor.getAlpha();
+        int alpha = bgColor != null ? bgColor.getAlpha() : 255;
         if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
             GraphicsConfiguration gc = getGraphicsConfiguration();
             GraphicsDevice gd = gc.getDevice();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Window/SetBackgroundNPE/SetBackgroundNPE.java	Tue Jul 07 17:05:50 2009 +0400
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+  @test
+  @bug 6853916
+  @summary Window.setBackground() should not throw NPE
+  @author anthony.petrov@sun.com: area=awt.toplevel
+  @run main SetBackgroundNPE
+*/
+
+import java.awt.Window;
+
+public class SetBackgroundNPE {
+    public static void main(String args[]) {
+        new Window(null).setBackground(null);
+    }
+}