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