8270269: Desktop.browse method fails if earlier CoInitialize call as COINIT_MULTITHREADED

Reviewed-by: aivanov
This commit is contained in:
Sergey Bylokhov 2023-12-12 18:30:41 +00:00
parent df4ed7eff7
commit b25ed57b76
2 changed files with 15 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -40,6 +40,8 @@ import java.net.URI;
import javax.swing.event.EventListenerList; import javax.swing.event.EventListenerList;
import sun.awt.shell.ShellFolder;
/** /**
* Concrete implementation of the interface {@code DesktopPeer} for * Concrete implementation of the interface {@code DesktopPeer} for
* the Windows platform. * the Windows platform.
@ -102,18 +104,20 @@ final class WDesktopPeer implements DesktopPeer {
} }
private void ShellExecute(File file, String verb) throws IOException { private void ShellExecute(File file, String verb) throws IOException {
String errMsg = ShellExecute(file.getAbsolutePath(), verb); String errMsg = ShellFolder.invoke(
() -> ShellExecute(file.getAbsolutePath(), verb));
if (errMsg != null) { if (errMsg != null) {
throw new IOException("Failed to " + verb + " " + file + ". Error message: " + errMsg); throw new IOException("Failed to " + verb + " " + file +
". Error message: " + errMsg);
} }
} }
private void ShellExecute(URI uri, String verb) throws IOException { private void ShellExecute(URI uri, String verb) throws IOException {
String errmsg = ShellExecute(uri.toString(), verb); String errmsg = ShellFolder.invoke(
() -> ShellExecute(uri.toString(), verb));
if (errmsg != null) { if (errmsg != null) {
throw new IOException("Failed to " + verb + " " + uri throw new IOException("Failed to " + verb + " " + uri +
+ ". Error message: " + errmsg); ". Error message: " + errmsg);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -85,24 +85,14 @@ JNIEXPORT jstring JNICALL Java_sun_awt_windows_WDesktopPeer_ShellExecute
// 6457572: ShellExecute possibly changes FPU control word - saving it here // 6457572: ShellExecute possibly changes FPU control word - saving it here
unsigned oldcontrol87 = _control87(0, 0); unsigned oldcontrol87 = _control87(0, 0);
HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | HINSTANCE retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL,
COINIT_DISABLE_OLE1DDE);
HINSTANCE retval;
DWORD error;
if (SUCCEEDED(hr)) {
retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL,
SW_SHOWNORMAL); SW_SHOWNORMAL);
error = ::GetLastError(); DWORD error = ::GetLastError();
::CoUninitialize();
}
_control87(oldcontrol87, 0xffffffff); _control87(oldcontrol87, 0xffffffff);
JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c); JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c);
JNU_ReleaseStringPlatformChars(env, verb_j, verb_c); JNU_ReleaseStringPlatformChars(env, verb_j, verb_c);
if (FAILED(hr)) {
return JNU_NewStringPlatform(env, L"CoInitializeEx() failed.");
}
if ((int)((intptr_t)retval) <= 32) { if ((int)((intptr_t)retval) <= 32) {
// ShellExecute failed. // ShellExecute failed.
LPTSTR buffer = NULL; LPTSTR buffer = NULL;