JDK-8289573 : [macos] Swing app fails when using -XstartOnFirstThread
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 11,17,18
  • Priority: P3
  • Status: New
  • Resolution: Unresolved
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2022-06-29
  • Updated: 2022-07-01
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
OS X Monterey 12.4, 32 gig iMac i7, OpenJDK 18.0.1.1

A DESCRIPTION OF THE PROBLEM :
This seems to be a regression from bug #7128597.  When building an app that uses AWT/Swing, if you use the -XstartOnFirstThread VM switch then it either locks or never shows a window.  This fails either creating a Frame directly in a main or within an invokeLater.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use this simple code (with or without the invokeLater, it doesn't make a difference, probably easier to check otherwise but I added this to test if that would be a fix):

package com.mycompany.testproject;

import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class TestProject {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
        JFrame frame=new JFrame();
        frame.setMinimumSize(new Dimension(1000, 500));
        frame.setVisible(true);
        });
    }
}

Add VM option -XstartOnFirstThread


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
You should get a single frame.
ACTUAL -
Nothing happens.  Removing the -XstartOnFirstThread gets you the expected results.

---------- BEGIN SOURCE ----------
public class TestProject {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
        JFrame frame=new JFrame();
        frame.setMinimumSize(new Dimension(1000, 500));
        frame.setVisible(true);
        });
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Removing -XstartOnFirstThread, but this isn't possible as libraries I'm using require it.

FREQUENCY : always



Comments
Issue is reproduced when executing the testcase with VM option -XstartOnFirstThread OS: Mac OS( BigSur 11.6) JDK 11.0.15.1: Fail JDK 17.0.3: Fail JDK 18.0.1.1: Fail No frame is loaded when executing testcase with VM Option -XstartOnFirstThread, however frame is loaded if VM option is not used.
01-07-2022