Subject: Bug#1621: X11 error with Java 17

From: Avner Tenne <[email-masked]>
Date: Sat, 13 Jan 2024 20:22:48 +0200

Package: x2goserver
Version: 4.1.0.3-9

I'm running x2go server on Centos 7.5 using KDE desktop manager.

I use the latest client version 4.1.2.2 from windows.

I'm running the following Java code using the Java 17 version.
public class TestDialog extends JDialog {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			TestDialog dialog = new TestDialog();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public TestDialog() {
		super();
		setPreferredSize(getPreferredSize());
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setLayout(new FlowLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			JLabel lblNewLabel = new JLabel("New label");
			contentPanel.add(lblNewLabel);
		}
		{
			JButton btnNewButton = new JButton("New button");
			contentPanel.add(btnNewButton);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}

}

When I use the x2go session type KDE I don't get any errors running my code.

But, when I use application session type using terminal mode I get the
following exception:
java.lang.NullPointerException: Cannot invoke
"sun.awt.X11.XBaseWindow.isVisible()" because "parent" is null
        at java.desktop/sun.awt.X11.XWindowPeer.setToplevelTransientFor(XWindowPeer.java:1688)
        at java.desktop/sun.awt.X11.XWindowPeer.postInit(XWindowPeer.java:253)
        at java.desktop/sun.awt.X11.XDecoratedPeer.postInit(XDecoratedPeer.java:105)
        at java.desktop/sun.awt.X11.XBaseWindow.init(XBaseWindow.java:184)
        at java.desktop/sun.awt.X11.XBaseWindow.<init>(XBaseWindow.java:259)
        at java.desktop/sun.awt.X11.XWindow.<init>(XWindow.java:147)
        at java.desktop/sun.awt.X11.XComponentPeer.<init>(XComponentPeer.java:111)
        at java.desktop/sun.awt.X11.XCanvasPeer.<init>(XCanvasPeer.java:42)
        at java.desktop/sun.awt.X11.XPanelPeer.<init>(XPanelPeer.java:48)
        at java.desktop/sun.awt.X11.XWindowPeer.<init>(XWindowPeer.java:134)
        at java.desktop/sun.awt.X11.XDecoratedPeer.<init>(XDecoratedPeer.java:62)
        at java.desktop/sun.awt.X11.XDialogPeer.<init>(XDialogPeer.java:40)
        at java.desktop/sun.awt.X11.XToolkit.createDialog(XToolkit.java:1084)
        at java.desktop/java.awt.Dialog.addNotify(Dialog.java:768)
        at java.desktop/java.awt.Dialog.conditionalShow(Dialog.java:917)
        at java.desktop/java.awt.Dialog.show(Dialog.java:1048)
        at java.desktop/java.awt.Component.show(Component.java:1728)
        at java.desktop/java.awt.Component.setVisible(Component.java:1675)
        at java.desktop/java.awt.Window.setVisible(Window.java:1036)
        at java.desktop/java.awt.Dialog.setVisible(Dialog.java:1016)
        at TestDialog.main(TestDialog.java:22)

Is there any external X2go/desktop session that is missing in order my
code will work fine.

Avner