Skip to content

Commit 70eb95f

Browse files
committed
8344187: Remove SecurityManager and related calls from java.instrument
Reviewed-by: alanb, amenkov
1 parent 922b12f commit 70eb95f

File tree

2 files changed

+6
-34
lines changed

2 files changed

+6
-34
lines changed

src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
package java.lang.instrument;
2727

28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
3028
import java.security.ProtectionDomain;
3129

3230
/*

src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 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
@@ -36,7 +36,6 @@
3636
import java.nio.file.Path;
3737
import java.nio.file.InvalidPathException;
3838
import java.net.URL;
39-
import java.security.AccessController;
4039
import java.security.CodeSource;
4140
import java.security.PrivilegedAction;
4241
import java.security.ProtectionDomain;
@@ -68,9 +67,7 @@ public class InstrumentationImpl implements Instrumentation {
6867
private static final String TRACE_USAGE_PROP_NAME = "jdk.instrument.traceUsage";
6968
private static final boolean TRACE_USAGE;
7069
static {
71-
PrivilegedAction<String> pa = () -> System.getProperty(TRACE_USAGE_PROP_NAME);
72-
@SuppressWarnings("removal")
73-
String s = AccessController.doPrivileged(pa);
70+
String s = System.getProperty(TRACE_USAGE_PROP_NAME);
7471
TRACE_USAGE = (s != null) && (s.isEmpty() || Boolean.parseBoolean(s));
7572
}
7673

@@ -100,9 +97,7 @@ public class InstrumentationImpl implements Instrumentation {
10097
String source = jarFile(nativeAgent);
10198
try {
10299
Path path = Path.of(source);
103-
PrivilegedAction<Path> pa = path::toAbsolutePath;
104-
@SuppressWarnings("removal")
105-
Path absolutePath = AccessController.doPrivileged(pa);
100+
Path absolutePath = path.toAbsolutePath();
106101
source = absolutePath.toString();
107102
} catch (InvalidPathException e) {
108103
// use original path
@@ -482,18 +477,6 @@ private TransformerManager findTransformerManager(ClassFileTransformer transform
482477
* Internals
483478
*/
484479

485-
486-
// Enable or disable Java programming language access checks on a
487-
// reflected object (for example, a method)
488-
@SuppressWarnings("removal")
489-
private static void setAccessible(final AccessibleObject ao, final boolean accessible) {
490-
AccessController.doPrivileged(new PrivilegedAction<Object>() {
491-
public Object run() {
492-
ao.setAccessible(accessible);
493-
return null;
494-
}});
495-
}
496-
497480
// Attempt to load and start an agent
498481
private void
499482
loadClassAndStartAgent( String classname,
@@ -553,7 +536,7 @@ public Object run() {
553536
!javaAgentClass.getModule().isNamed()) {
554537
// If the java agent class is in an unnamed module, the java agent class can be non-public.
555538
// Suppress access check upon the invocation of the premain/agentmain method.
556-
setAccessible(m, true);
539+
m.setAccessible(true);
557540
}
558541

559542
// invoke the 1 or 2-arg method
@@ -665,23 +648,14 @@ private void trace(String methodName) {
665648
* Returns the possibly-bnull code source of the given class.
666649
*/
667650
private static URL codeSource(Class<?> clazz) {
668-
PrivilegedAction<ProtectionDomain> pa = clazz::getProtectionDomain;
669-
@SuppressWarnings("removal")
670-
CodeSource cs = AccessController.doPrivileged(pa).getCodeSource();
651+
CodeSource cs = clazz.getProtectionDomain().getCodeSource();
671652
return (cs != null) ? cs.getLocation() : null;
672653
}
673654

674655
/**
675656
* Holder for StackWalker object.
676657
*/
677658
private static class HolderStackWalker {
678-
static final StackWalker walker;
679-
static {
680-
PrivilegedAction<StackWalker> pa = () ->
681-
StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
682-
@SuppressWarnings("removal")
683-
StackWalker w = AccessController.doPrivileged(pa);
684-
walker = w;
685-
}
659+
static final StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
686660
}
687661
}

0 commit comments

Comments
 (0)