JDK-8229810 : [macos] NullPointerException getting bounds of GraphicsConfiguration
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 11,12.0.2,13,14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2019-07-22
  • Updated: 2022-06-27
  • Resolved: 2019-10-10
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 11 JDK 13 JDK 14
11.0.6-oracleFixed 13.0.4Fixed 14 b19Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
macOS Mojave 10.14.5 (MacBook Pro)

openjdk version "12.0.2" 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 12.0.2+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 12.0.2+10, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
The method java.awt.GraphicsConfiguration#getBounds can throw a NullPointerException when disconnecting displays.

REGRESSION : Last worked in version 11.0.4

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code on a MacBook Pro.

While that is running:
1) Plug in an external display to the laptop
2) Close the laptop lid
3) Unplug the external display
-> Exception is thrown here
4) Open the laptop lid

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception is thrown
ACTUAL -
Exception in thread "main" java.lang.NullPointerException
	at java.desktop/sun.awt.CGraphicsDevice.getBounds(CGraphicsDevice.java:116)
	at java.desktop/sun.awt.CGraphicsConfig.getBounds(CGraphicsConfig.java:57)
	at Main.main(Main.java:10)

---------- BEGIN SOURCE ----------
import java.awt.*;

public class Main {

    public static void main(String[] args) {
        while (true) {
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            for (GraphicsDevice gd : ge.getScreenDevices()) {
                GraphicsConfiguration gc = gd.getDefaultConfiguration();
                gc.getBounds();
            }
        }
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Catch the exception and ignore it.

FREQUENCY : occasionally



Comments
Fix request (13u) The patch applies cleanly, the provided reproducer fails without fix and passes with the fix.
19-05-2020

Fix request (11u) I would like to downport this for 11.0.6-oracle I had to do a trivial resolve: http://cr.openjdk.java.net/~goetz/wr19/8229810-mac_NPE_GraphicsConf/ http://mail.openjdk.java.net/pipermail/jdk-updates-dev/2019-November/002125.html
19-11-2019

URL: https://hg.openjdk.java.net/jdk/jdk/rev/a9b346a481d7 User: psadhukhan Date: 2019-10-15 09:43:32 +0000
15-10-2019

URL: https://hg.openjdk.java.net/jdk/client/rev/a9b346a481d7 User: serb Date: 2019-10-10 07:07:49 +0000
10-10-2019

Looks like the root cause is a lack of synchronization, we create the GraphicsDevice under a special lock which is used to access the list of devices, but initialize the device w/o this lock. SO it is possible that we create the device, add it to the list of devices, and before we initialize it the user could access the not fully initialized object. This is why it is intermittent since it depends on the timings.
16-08-2019

Reported as a regression in macOS X 10.14.5 with JDK 12.0.2, method java.awt.GraphicsConfiguration#getBounds throw a NullPointerException when disconnecting displays. As per description, this has worked fine with 11.0.4. Verified this with attached test case and additional instructions in macOS 10.13.5 and the issue does not reproduce with reported version 12.0.2. However, this still need to check with reported mac OS version 10.14.5.
16-08-2019