Skip to content

Commit 2fe16da

Browse files
author
duke
committedMay 2, 2024
Automatic merge of jdk:master into master
2 parents 038a063 + 9912abf commit 2fe16da

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed
 

‎src/java.desktop/unix/classes/sun/awt/screencast/TokenStorage.java

+46-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, 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
@@ -37,6 +37,8 @@
3737
import java.nio.file.WatchKey;
3838
import java.nio.file.WatchService;
3939
import java.nio.file.attribute.PosixFilePermission;
40+
import java.security.AccessController;
41+
import java.security.PrivilegedAction;
4042
import java.util.Arrays;
4143
import java.util.HashSet;
4244
import java.util.LinkedHashSet;
@@ -58,6 +60,7 @@
5860
* The restore token allows the ScreenCast session to be restored
5961
* with previously granted screen access permissions.
6062
*/
63+
@SuppressWarnings("removal")
6164
final class TokenStorage {
6265

6366
private TokenStorage() {}
@@ -69,8 +72,24 @@ private TokenStorage() {}
6972
private static final Path PROPS_PATH;
7073
private static final Path PROP_FILENAME;
7174

75+
private static void doPrivilegedRunnable(Runnable runnable) {
76+
AccessController.doPrivileged(new PrivilegedAction<Void>() {
77+
@Override
78+
public Void run() {
79+
runnable.run();
80+
return null;
81+
}
82+
});
83+
}
84+
7285
static {
73-
PROPS_PATH = setupPath();
86+
PROPS_PATH = AccessController.doPrivileged(new PrivilegedAction<Path>() {
87+
@Override
88+
public Path run() {
89+
return setupPath();
90+
}
91+
});
92+
7493
if (PROPS_PATH != null) {
7594
PROP_FILENAME = PROPS_PATH.getFileName();
7695
if (SCREENCAST_DEBUG) {
@@ -192,9 +211,9 @@ public void run() {
192211
}
193212

194213
if (kind == ENTRY_CREATE) {
195-
setFilePermission(PROPS_PATH);
214+
doPrivilegedRunnable(() -> setFilePermission(PROPS_PATH));
196215
} else if (kind == ENTRY_MODIFY) {
197-
readTokens(PROPS_PATH);
216+
doPrivilegedRunnable(() -> readTokens(PROPS_PATH));
198217
} else if (kind == ENTRY_DELETE) {
199218
synchronized (PROPS) {
200219
PROPS.clear();
@@ -207,24 +226,31 @@ public void run() {
207226
}
208227
}
209228

229+
private static WatchService watchService;
230+
210231
private static void setupWatch() {
211-
try {
212-
WatchService watchService =
213-
FileSystems.getDefault().newWatchService();
232+
doPrivilegedRunnable(() -> {
233+
try {
234+
watchService =
235+
FileSystems.getDefault().newWatchService();
214236

215-
PROPS_PATH
216-
.getParent()
217-
.register(watchService,
218-
ENTRY_CREATE,
219-
ENTRY_DELETE,
220-
ENTRY_MODIFY);
237+
PROPS_PATH
238+
.getParent()
239+
.register(watchService,
240+
ENTRY_CREATE,
241+
ENTRY_DELETE,
242+
ENTRY_MODIFY);
221243

222-
new WatcherThread(watchService).start();
223-
} catch (Exception e) {
224-
if (SCREENCAST_DEBUG) {
225-
System.err.printf("Token storage: failed to setup " +
226-
"file watch %s\n", e);
244+
} catch (Exception e) {
245+
if (SCREENCAST_DEBUG) {
246+
System.err.printf("Token storage: failed to setup " +
247+
"file watch %s\n", e);
248+
}
227249
}
250+
});
251+
252+
if (watchService != null) {
253+
new WatcherThread(watchService).start();
228254
}
229255
}
230256

@@ -276,7 +302,7 @@ private static void storeTokenFromNative(String oldToken,
276302
}
277303

278304
if (changed) {
279-
store("save tokens");
305+
doPrivilegedRunnable(() -> store("save tokens"));
280306
}
281307
}
282308
}
@@ -331,7 +357,7 @@ static Set<TokenItem> getTokens(List<Rectangle> affectedScreenBounds) {
331357
.toList();
332358
}
333359

334-
removeMalformedRecords(malformed);
360+
doPrivilegedRunnable(() -> removeMalformedRecords(malformed));
335361

336362
// 1. Try to find exact matches
337363
for (TokenItem tokenItem : allTokenItems) {

‎test/jdk/jdk/classfile/OptionsTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
*
55
* This code is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation. Oracle designates this
8-
* particular file as subject to the "Classpath" exception as provided
9-
* by Oracle in the LICENSE file that accompanied this code.
7+
* published by the Free Software Foundation.
108
*
119
* This code is distributed in the hope that it will be useful, but WITHOUT
1210
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

0 commit comments

Comments
 (0)
Failed to load comments.