-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java + Windows RDP disconnect causes Java Headless Exception #1203
Comments
Can this issue be monkey-patched? |
Code demonstrating issue: import javax.swing.*;
import java.awt.*;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) throws InterruptedException {
var delay = 10;
var isHeadless = GraphicsEnvironment.isHeadless();
System.out.printf("1) Is headless: %s.%n", isHeadless);
System.out.printf("Sleeping %,d seconds.%n", delay);
System.out.printf("""
DISCONNECT YOUR REMOTE DESKTOP CONNECTION NOW!
RECONNECT AFTER %,d SECONDS.
""", delay);
Thread.sleep(delay * 1_000);
System.out.println("Drawing progress bar");
ProgressMonitor p = new ProgressMonitor(null, "Test progressbar", "My note", 0, 100);
for (int i = 0; i < 100; i++) {
p.setProgress(i);
Thread.sleep(250);
}
isHeadless = GraphicsEnvironment.isHeadless();
System.out.printf("2) Is headless: %s.%n", isHeadless);
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
} Error log: "C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2024.3.1\lib\idea_rt.jar=59072:C:\Program Files\JetBrains\IntelliJ IDEA 2024.3.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\admin.NEWSRX\git\rdp-crashes\out\production\rdp-crashes Main
Picked up JAVA_TOOL_OPTIONS: -Xmx6144m -Dlog4j2.formatMsgNoLookups=true
1) Is headless: false.
Sleeping 10 seconds.
DISCONNECT YOUR REMOTE DESKTOP CONNECTION NOW!
RECONNECT AFTER 10 SECONDS.
Drawing progress bar
Exception in thread "main" java.awt.AWTError: no screen devices
at java.desktop/sun.awt.Win32GraphicsEnvironment.getDefaultScreenDevice(Win32GraphicsEnvironment.java:101)
at java.desktop/sun.font.FontDesignMetrics.getDefaultFrc(FontDesignMetrics.java:157)
at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:274)
at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1242)
at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1700)
at java.desktop/javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:360)
at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:542)
at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getMinimumSize(BasicButtonUI.java:532)
at java.desktop/javax.swing.JComponent.getMinimumSize(JComponent.java:1814)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:818)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:751)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:206)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:160)
at java.desktop/javax.swing.JComponent.setUI(JComponent.java:740)
at java.desktop/javax.swing.JOptionPane.setUI(JOptionPane.java:1858)
at java.desktop/javax.swing.JOptionPane.updateUI(JOptionPane.java:1880)
at java.desktop/javax.swing.JOptionPane.<init>(JOptionPane.java:1845)
at java.desktop/javax.swing.ProgressMonitor$ProgressOptionPane.<init>(ProgressMonitor.java:161)
at java.desktop/javax.swing.ProgressMonitor.setProgress(ProgressMonitor.java:291)
at Main.main(Main.java:20)
Process finished with exit code 1 |
Looks to be https://bugs.openjdk.org/browse/JDK-8336862 Does setting |
No this does not help. "C:\Program Files\Eclipse Adoptium\jdk-21.0.5.11-hotspot\bin\java.exe" -Djava.awt.headless=false "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2024.3.1\lib\idea_rt.jar=59410:C:\Program Files\JetBrains\IntelliJ IDEA 2024.3.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\admin.NEWSRX\git\rdp-crashes\out\production\rdp-crashes Main
Picked up JAVA_TOOL_OPTIONS: -Xmx6144m -Dlog4j2.formatMsgNoLookups=true
1) Is headless: false.
Sleeping 10 seconds.
DISCONNECT YOUR REMOTE DESKTOP CONNECTION NOW!
RECONNECT AFTER 10 SECONDS.
Drawing progress bar
Exception in thread "main" java.awt.AWTError: no screen devices
at java.desktop/sun.awt.Win32GraphicsEnvironment.getDefaultScreenDevice(Win32GraphicsEnvironment.java:101)
at java.desktop/sun.font.FontDesignMetrics.getDefaultFrc(FontDesignMetrics.java:157)
at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:274)
at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1242)
at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1700)
at java.desktop/javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:360)
at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:542)
at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getMinimumSize(BasicButtonUI.java:532)
at java.desktop/javax.swing.JComponent.getMinimumSize(JComponent.java:1814)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:818)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:751)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:206)
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:160)
at java.desktop/javax.swing.JComponent.setUI(JComponent.java:740)
at java.desktop/javax.swing.JOptionPane.setUI(JOptionPane.java:1858)
at java.desktop/javax.swing.JOptionPane.updateUI(JOptionPane.java:1880)
at java.desktop/javax.swing.JOptionPane.<init>(JOptionPane.java:1845)
at java.desktop/javax.swing.ProgressMonitor$ProgressOptionPane.<init>(ProgressMonitor.java:161)
at java.desktop/javax.swing.ProgressMonitor.setProgress(ProgressMonitor.java:291)
at Main.main(Main.java:20)
Process finished with exit code 1 |
Hrmmmm... just tried using JetBrains JDK in Intellij version 21.0.5 and the problem does not occur. |
OK So we've downgraded all the physical desktop systems to 21.0.3 and RDP disconnects no longer cause Java to crash. As we use AdoptOpenJDK, we told it to skip the current 21.0.5 release for updating. -Mike/NewsRx |
The reason why this works in JetBrains Runtime (JBR) is because the problem has been "solved" directly in JBR. However, there are no changes and no proposals for the OpenJDK at the present time. Currently, the only known workaround is to stick with Java 21.0.3 (Java 17.0.11). However, as it does not provide fixes for new vulnerabilities and other issues, it is not a long-term solution. |
Please provide a brief summary of the bug
Starting with Java 17.0.12 and 21.0.4 Java fails with a Headless exception when running a full GUI app via RDP and the RDP session is disconnected. The remote desktop is running and can be reconnected with. All non-Java apps are still running and updating their UI's just fine. It is only Java GUI apps that are crashing.
If the Java program attempts to do GUI operations such as create a modal progress bar while the RDP session is disconnected, a Headless exception is thrown, even though the environment is not headless, just disconnected.
This seems to be related to https://bugs.openjdk.org/browse/JDK-8340992 and https://bugs.openjdk.org/browse/JDK-8336862 but there are no workarounds provided.
Is there a workaround that can be done runtime?
The only workarounds we can come up with are:
This would also seem to be breaking of the "contract" where minor point releases are not supposed to cause breaking changes.
We mostly use simple apps composed of
JFrames
,JTextComponents
, andProgressMonitor
with a couple of self-hostedJediTerm
applications.Did you test with the latest update version?
Please provide steps to reproduce where possible
Create an app with opens and closes windows with time delays.
Start the app on Windows in an RDP session.
Disconnect from the RDP session.
Wait till the app should have opened and closed any test windows.
Reconnect to the RDP session.
Expected Results
The app to create UI components in the disconnected RDP session, just like all other non-Java apps are capable of.
Actual Results
GUI apps should keep running when a remote desktop session is disconnected. They should not suddenly fail reporting that GUI operations are not possible.
What Java Version are you using?
Picked up JAVA_TOOL_OPTIONS: -Xmx6144m -Dlog4j2.formatMsgNoLookups=true openjdk version "21.0.5" 2024-10-15 LTS OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.5+11 (build 21.0.5+11-LTS, mixed mode, sharing) PS C:\Users\admin.NEWSRX>
What is your operating system and platform?
Windows specifications:
How did you install Java?
https://github.com/tushev/aojdk-updatewatcher/wiki
Did it work before?
Did you test with other Java versions?
Every point release after 21.0.3 that AdoptOpenJDK reported in need of updating.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: