JDK-8270269 : Desktop.browse method fails if earlier CoInitialize call as COINIT_MULTITHREADED
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 16,17,18,21,22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: x86_64
  • Submitted: 2021-07-05
  • Updated: 2023-12-18
  • Resolved: 2023-12-12
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 23
23 b02Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows / Window 10/ JDK 16 and JDK 17ea

A DESCRIPTION OF THE PROBLEM :
Desktop.browse native peer implementation attempts to CoInitializeEx as COINIT_APARTMENTTHREADED and will fail if there has been a prior call (eg. via JNI)  to CoInitialize as COINIT_MULTITHREADED. This problem is new in JDK 16/17ea - see awt_Desktop.cpp:88 in JDK source for point of failure.

REGRESSION : Last worked in version 15

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a native /JNI call that calls CoInitializeEx(NULL, COINIT_MULTITHREADED) and call the native prior to calling Dekstop.getDesktop().browse(url).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
URL will open in system assigned browser (JDK 15 and earlier)
ACTUAL -
Exception in thread "main" java.io.IOException: Failed to open https://www.google.com. Error message: CoInitializeEx() failed.
	at java.desktop/sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:115)
	at java.desktop/sun.awt.windows.WDesktopPeer.browse(WDesktopPeer.java:101)
	at java.desktop/java.awt.Desktop.browse(Desktop.java:530)
....

---------- BEGIN SOURCE ----------
// approximate example cpp and java since not sure what is expected for 
// a native/java bug  test case

---- native ---
void Demo::initCom() {
    HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
    if (hr != S_FALSE)    
            EXIT_ON_ERROR(hr);    // some sort of handling
}

-- java ---
 public static void main(String [] args) throws URISyntaxException, IOException {        
        Demo.initCom(); 
        Desktop desktop = Desktop.getDesktop();
        desktop.browse(new URI("https://www.google.com"));
    }


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

CUSTOMER SUBMITTED WORKAROUND :
No workaround found.

FREQUENCY : always



Comments
Changeset: b25ed57b Author: Sergey Bylokhov <serb@openjdk.org> Date: 2023-12-12 18:30:41 +0000 URL: https://git.openjdk.org/jdk/commit/b25ed57b764fc485e4e8ca4118ffb1cc70fdfe7f
12-12-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17010 Date: 2023-12-07 03:03:59 +0000
07-12-2023

https://stackoverflow.com/questions/67876108/desktop-browse-fails-with-jdk-17
28-10-2021

I can take a look to this issue.
11-09-2021