JDK-6837004 : java.awt.GraphicsDevice.setFullScreenWindow throws NPE for windows with background color not set
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-05-04
  • Updated: 2012-03-22
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b59Fixed
Related Reports
Relates :  
Description
The following code:

public class Temp {
    public static void main(String[] args) {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice[] devices = ge.getScreenDevices();
        for (GraphicsDevice device : devices) {
            Frame w = new Frame();
            //w.setBackground(Color.BLACK);
            device.setFullScreenWindow(w);
        }
    }
}

throws NPE on JDK7 b57 like the following:

Exception in thread "main" java.lang.NullPointerException
	at java.awt.GraphicsDevice.setFullScreenWindow(GraphicsDevice.java:285)
	at sun.awt.Win32GraphicsDevice.setFullScreenWindow(Win32GraphicsDevice.java:365)
	at shapedtrans.Temp.main(Temp.java:12)
        ...

Code sample works for JDK6

Comments
EVALUATION Approved for JDK 7 M3 build 59.
05-05-2009

SUGGESTED FIX --- a/src/share/classes/java/awt/GraphicsDevice.java Tue Apr 21 11:35:52 2009 +0400 +++ b/src/share/classes/java/awt/GraphicsDevice.java Tue May 05 14:46:13 2009 +0400 @@ -282,7 +282,7 @@ w.setOpacity(1.0f); } Color bgColor = w.getBackground(); - if (bgColor.getAlpha() < 255) { + if ((bgColor != null) && (bgColor.getAlpha() < 255)) { bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 255); w.setBackground(bgColor);
05-05-2009

EVALUATION Regression of 6802853.
04-05-2009

EVALUATION Window background may be null, however there is no such check in GraphicsDevice.setFullScreenWindow(): Color bgColor = w.getBackground(); --> if (bgColor.getAlpha() < 255) { bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 255); w.setBackground(bgColor); }
04-05-2009