JDK-8076313 : GraphicsEnvironment does not detect changes in count of monitors on Linux OS
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u76,8u40,9,11,12,13,14,15
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: generic
  • Submitted: 2015-03-31
  • Updated: 2022-06-27
  • Resolved: 2021-02-03
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 17
11-poolUnresolved 17 b08Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
JDK 9, JDK 8u40, JDK 7u76

ADDITIONAL OS VERSION INFORMATION :
Ubuntu 14.04 OS

A DESCRIPTION OF THE PROBLEM :
On Linux OS the method "java.awt.GraphicsEnvironment.getScreenDevices()" returns wrong number of "java.awt.GraphicsDevice" objects after an additional monitor is plugged in or plugged out.

For example, on the system with two monitors the attached test case produces the following output.

Scenario #1 – The additional monitor is plugged out:
These monitors correctly recognized when Java started: 
:0.0 1280x1024 0,0/1280x1024 
:0.1 1920x1200 1280,0/1920x1200 
But after plugging out the monitor Java returns wrong array: 
:0.0 1280x1024 0,0/1280x1024 <-- this one actually does not exist 
:0.1 1920x1200 1280,0/1920x1200 

Scenario #2 – The additional monitor is plugged in:
Default monitor correctly recognized when Java started: 
:0.0 1920x1200 0,0/1920x1200 
But after plugging in the monitor Java returns wrong array: 
:0.0 1280x1024 0,0/3200x1200 <-- 2 screens joined into 1 pseudo-screen 

The issue is not reproducible on OS X and MS Windows OS.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Scenario #1:
1. Plug in the additional monitor.
2. Compile and run the test case attached to the bug as "GetScreenDevicesReturnsIncorrectResult.java" file with JDK to be tested.
3. In the test case window click "LOG" button and verify that all monitors available in the OS became listed in the test case window.
4. Plug out the additional monitor.
5. In the test case window click "LOG" button. The bug is reproduced, if the plugged out monitor still became listed in the test case window.

Scenario #2:
1. Plug out the additional monitor.
2. Compile and run the test case attached to the bug as "GetScreenDevicesReturnsIncorrectResult.java" file with JDK to be tested.
3. In the test case window click "LOG" button and verify that the plugged out monitor did not become listed in the test case window.
4. Plug in the additional monitor.
5. In the test case window click "LOG" button. The bug is reproduced, if the plugged in monitor still did not become listed in the test case window.
Comments
Changeset: 98a76921 Author: Sergey Bylokhov <serb@openjdk.org> Date: 2021-02-03 03:41:53 +0000 URL: https://git.openjdk.java.net/jdk/commit/98a76921
03-02-2021

Current attempt to split the native data and drop its old usage: http://cr.openjdk.java.net/~serb/8076313/split_native_device_list/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c.sdiff.html http://cr.openjdk.java.net/~serb/8076313/split_native_device_list/ Some unsolved issues still exists in the text rendering because X11TextRenderer.c#AWTDrawGlyphList() uses for some reason default GC directly. Another direct usage of screen data exists in awt_InputMethod.c on AIX, JDK-8239583
21-02-2020

Native data reinitialization: http://cr.openjdk.java.net/~serb/8076313/webrev.00 But we still have a lot of places where we access these native data w/o initialization, which cause crashes.
05-10-2019

The actual code of the screen change notification is simple: http://cr.openjdk.java.net/~serb/8076313/notification/src/java.desktop/unix/classes/sun/awt/X11GraphicsEnvironment.java.sdiff.html But we need to eliminate the statics data: http://cr.openjdk.java.net/~serb/8076313/notification/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c.sdiff.html I have tried to reinitialize these native data when necessary, but we access it from the different places w/o any synchronizations, and it is an easy path to the use-after-free. Avery use of this data should be drooped in the same way as in:https://bugs.openjdk.java.net/browse/JDK-8214918 Or we can move this information to the java side.
19-04-2019

During of the fix development I have been stuck on the code which caches the xinerama parameters in the native code. A few initial attempts to update this code were resulted to the crashes because across our code we assumed that this data is never changed and we access to it w/o any synchronization. Another problem is an assumption that xinerama/non-xinerame mode is always the same during the life time of the application, which is wrong because we can be moved from one state to another. Based on above I have moved the fix to jdk13.
05-12-2018

NOTE: This Enhancement will be retargeted to "13" in case this issue is still Unresolved by Mon, Dec 10 3am Pacific Time Mon Dec 10 (Pre Integration Testing deadline) to meet JDK 12 RDP1 (Dec 13th) milestone [1]. No more Enhancements in JDK 12 beyond RDP1 in accordance with RDP1 definition [2]. [1] http://mail.openjdk.java.net/pipermail/jdk-dev/2018-September/001984.html [2] http://openjdk.java.net/jeps/3
04-12-2018

Reminder: Dec 13 is a deadline (JDK 12 RDP1) to push a code of Enhancement into mainstream repo before JDK 12 repo fork
27-11-2018

This functionality never worked for Linux. It requires some extensive changes in the code, so it more an RFE rather than a bug.
17-02-2016

The test case was attached to the bug record as "GetScreenDevicesReturnsIncorrectResult.java" file. The bug was reproduced by means of the attached test case on 32-bit Ubuntu 14.04 OS with JDK 9 b88, JDK 8u65 b17, JDK 7u91 b15.
28-10-2015