Skip to content

Commit 5eb51cd

Browse files
committed
8270269: Desktop.browse method fails if earlier CoInitialize call as COINIT_MULTITHREADED
Backport-of: b25ed57b764fc485e4e8ca4118ffb1cc70fdfe7f
1 parent 89b614d commit 5eb51cd

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/java.desktop/windows/classes/sun/awt/windows/WDesktopPeer.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,6 +40,8 @@
4040

4141
import javax.swing.event.EventListenerList;
4242

43+
import sun.awt.shell.ShellFolder;
44+
4345
/**
4446
* Concrete implementation of the interface {@code DesktopPeer} for
4547
* the Windows platform.
@@ -102,18 +104,20 @@ public void browse(URI uri) throws IOException {
102104
}
103105

104106
private void ShellExecute(File file, String verb) throws IOException {
105-
String errMsg = ShellExecute(file.getAbsolutePath(), verb);
107+
String errMsg = ShellFolder.invoke(
108+
() -> ShellExecute(file.getAbsolutePath(), verb));
106109
if (errMsg != null) {
107-
throw new IOException("Failed to " + verb + " " + file + ". Error message: " + errMsg);
110+
throw new IOException("Failed to " + verb + " " + file +
111+
". Error message: " + errMsg);
108112
}
109113
}
110114

111115
private void ShellExecute(URI uri, String verb) throws IOException {
112-
String errmsg = ShellExecute(uri.toString(), verb);
113-
116+
String errmsg = ShellFolder.invoke(
117+
() -> ShellExecute(uri.toString(), verb));
114118
if (errmsg != null) {
115-
throw new IOException("Failed to " + verb + " " + uri
116-
+ ". Error message: " + errmsg);
119+
throw new IOException("Failed to " + verb + " " + uri +
120+
". Error message: " + errmsg);
117121
}
118122
}
119123

src/java.desktop/windows/native/libawt/windows/awt_Desktop.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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
8585

8686
// 6457572: ShellExecute possibly changes FPU control word - saving it here
8787
unsigned oldcontrol87 = _control87(0, 0);
88-
HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED |
89-
COINIT_DISABLE_OLE1DDE);
90-
HINSTANCE retval;
91-
DWORD error;
92-
if (SUCCEEDED(hr)) {
93-
retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL,
94-
SW_SHOWNORMAL);
95-
error = ::GetLastError();
96-
::CoUninitialize();
97-
}
88+
HINSTANCE retval = ::ShellExecute(NULL, verb_c, fileOrUri_c, NULL, NULL,
89+
SW_SHOWNORMAL);
90+
DWORD error = ::GetLastError();
9891
_control87(oldcontrol87, 0xffffffff);
9992

10093
JNU_ReleaseStringPlatformChars(env, fileOrUri_j, fileOrUri_c);
10194
JNU_ReleaseStringPlatformChars(env, verb_j, verb_c);
10295

103-
if (FAILED(hr)) {
104-
return JNU_NewStringPlatform(env, L"CoInitializeEx() failed.");
105-
}
10696
if ((int)((intptr_t)retval) <= 32) {
10797
// ShellExecute failed.
10898
LPTSTR buffer = NULL;

0 commit comments

Comments
 (0)