JDK-8288854 : getLocalGraphicsEnvironment() on for multi-screen setups throws exception NPE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 17,19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-06-15
  • Updated: 2022-12-29
  • Resolved: 2022-07-02
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 17 JDK 19 JDK 20
17.0.7Fixed 19 b30Fixed 20Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Linux - Centos 7

A DESCRIPTION OF THE PROBLEM :
See bugs.freebsd.org Bug 264356 - java/openjdk17: java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() on for multi-screen setups throws exception: Cannot read the array length because "this.screens" is null


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run java app that uses call to getLocalGraphicsEnvironment  on multi-screen display with Xinerama disabled - display to screen number not zero.
As described in the freebsd bug report - It is easy to duplicate using xephyr:
Xephyr :3 -screen 800x600 -screen 800x600


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Program should run
ACTUAL -
Null Pointer Exception

---------- BEGIN SOURCE ----------
See above
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Fix suggested in above bug report.

FREQUENCY : always



Comments
A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/994 Date: 2022-12-29 07:43:26 +0000
29-12-2022

Fix request (17u) Clean backport. Fix for a regression introduced in jdk17 b08. Verified by the "steps to reproduce" above. The jdk_desktop tests are green. Review 17u-dev: https://github.com/openjdk/jdk17u-dev/pull/994
29-12-2022

Changeset: cfc9a881 Author: Sergey Bylokhov <serb@openjdk.org> Date: 2022-07-02 00:25:20 +0000 URL: https://git.openjdk.org/jdk19/commit/cfc9a881afd300bd7c1ce784287d1669308e89fc
02-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk19/pull/81 Date: 2022-06-27 21:17:54 +0000
28-06-2022

To reproduce the bug on Linux the xinerama should be disabled and the non zero screen should be set as default. 1. Xephyr :3 -screen 800x600 -screen 800x600 2. export DISPLAY=:3.1 3. java -jar SwingSet2.jar Note that DISPLAY=:3.0 will work fine.
25-06-2022

Could be some difference in how X11 works in FreeBSD.
25-06-2022

The issue supposedly starts from JDK 17 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264356 Exception in thread "main" java.lang.ExceptionInInitializerError at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:106) at GraphEnv.main(GraphEnv.java:18) Caused by: java.lang.NullPointerException: Cannot read the array length because "this.screens" is null at java.desktop/sun.awt.X11GraphicsEnvironment.initDevices(X11GraphicsEnvironment.java:235) at java.desktop/sun.awt.X11GraphicsEnvironment.rebuildDevices(X11GraphicsEnvironment.java:216) at java.desktop/sun.awt.X11GraphicsEnvironment.<init>JDK 17 is where the actual code which NPEs was updated https://bugs.openjdk.org/browse/JDK-8076313 I say "updated" not "added" since screens being null would have caused an NPE in the old code too. But I'm not sure the old code actually refreshed monitors - that was the issue being fixed - and the description reads like it was on initialisation not adding a screen .. so there may be a hole.
21-06-2022

More information: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264356
21-06-2022