Skip to content

Commit 691e692

Browse files
author
Alan Bateman
committed
8345565: Remove remaining SecurityManager motivated APIs from sun.reflect.util
Reviewed-by: mullan, rriggs, liach
1 parent 97b8a09 commit 691e692

File tree

10 files changed

+7
-258
lines changed

10 files changed

+7
-258
lines changed

src/java.base/share/classes/java/io/ObjectInputStream.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import jdk.internal.event.DeserializationEvent;
4343
import jdk.internal.misc.Unsafe;
4444
import jdk.internal.util.ByteArray;
45-
import sun.reflect.misc.ReflectUtil;
4645

4746
/**
4847
* An ObjectInputStream deserializes primitive data and objects previously
@@ -1828,12 +1827,6 @@ private ObjectStreamClass readClassDesc(boolean unshared)
18281827
};
18291828
}
18301829

1831-
private boolean isCustomSubclass() {
1832-
// Return true if this class is a custom subclass of ObjectInputStream
1833-
return getClass().getClassLoader()
1834-
!= ObjectInputStream.class.getClassLoader();
1835-
}
1836-
18371830
/**
18381831
* Reads in and returns class descriptor for a dynamic proxy class. Sets
18391832
* passHandle to proxy class descriptor's assigned handle. If proxy class
@@ -1879,12 +1872,6 @@ private ObjectStreamClass readProxyDesc(boolean unshared)
18791872
} else if (!Proxy.isProxyClass(cl)) {
18801873
throw new InvalidClassException("Not a proxy");
18811874
} else {
1882-
// ReflectUtil.checkProxyPackageAccess makes a test
1883-
// equivalent to isCustomSubclass so there's no need
1884-
// to condition this call to isCustomSubclass == true here.
1885-
ReflectUtil.checkProxyPackageAccess(
1886-
getClass().getClassLoader(),
1887-
cl.getInterfaces());
18881875
// Filter the interfaces
18891876
for (Class<?> clazz : cl.getInterfaces()) {
18901877
filterCheck(clazz, -1);
@@ -1954,12 +1941,9 @@ private ObjectStreamClass readNonProxyDesc(boolean unshared)
19541941
Class<?> cl = null;
19551942
ClassNotFoundException resolveEx = null;
19561943
bin.setBlockDataMode(true);
1957-
final boolean checksRequired = isCustomSubclass();
19581944
try {
19591945
if ((cl = resolveClass(readDesc)) == null) {
19601946
resolveEx = new ClassNotFoundException("null class");
1961-
} else if (checksRequired) {
1962-
ReflectUtil.checkPackageAccess(cl);
19631947
}
19641948
} catch (ClassNotFoundException ex) {
19651949
resolveEx = ex;

src/java.base/share/classes/java/io/ObjectOutputStream.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import jdk.internal.util.ByteArray;
3636
import jdk.internal.access.JavaLangAccess;
3737
import jdk.internal.access.SharedSecrets;
38-
import sun.reflect.misc.ReflectUtil;
3938

4039
import static jdk.internal.util.ModifiedUtf.putChar;
4140
import static jdk.internal.util.ModifiedUtf.utfLen;
@@ -1170,12 +1169,6 @@ private void writeClassDesc(ObjectStreamClass desc, boolean unshared)
11701169
}
11711170
}
11721171

1173-
private boolean isCustomSubclass() {
1174-
// Return true if this class is a custom subclass of ObjectOutputStream
1175-
return getClass().getClassLoader()
1176-
!= ObjectOutputStream.class.getClassLoader();
1177-
}
1178-
11791172
/**
11801173
* Writes class descriptor representing a dynamic proxy class to stream.
11811174
*/
@@ -1193,9 +1186,6 @@ private void writeProxyDesc(ObjectStreamClass desc, boolean unshared)
11931186
}
11941187

11951188
bout.setBlockDataMode(true);
1196-
if (isCustomSubclass()) {
1197-
ReflectUtil.checkPackageAccess(cl);
1198-
}
11991189
annotateProxyClass(cl);
12001190
bout.setBlockDataMode(false);
12011191
bout.writeByte(TC_ENDBLOCKDATA);
@@ -1222,9 +1212,6 @@ private void writeNonProxyDesc(ObjectStreamClass desc, boolean unshared)
12221212

12231213
Class<?> cl = desc.forClass();
12241214
bout.setBlockDataMode(true);
1225-
if (cl != null && isCustomSubclass()) {
1226-
ReflectUtil.checkPackageAccess(cl);
1227-
}
12281215
annotateClass(cl);
12291216
bout.setBlockDataMode(false);
12301217
bout.writeByte(TC_ENDBLOCKDATA);

src/java.base/share/classes/java/lang/Class.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import java.util.Arrays;
6161
import java.util.Collection;
6262
import java.util.HashMap;
63-
import java.util.HashSet;
6463
import java.util.LinkedHashMap;
6564
import java.util.LinkedHashSet;
6665
import java.util.List;
@@ -91,7 +90,6 @@
9190
import sun.reflect.generics.repository.ConstructorRepository;
9291
import sun.reflect.generics.scope.ClassScope;
9392
import sun.reflect.annotation.*;
94-
import sun.reflect.misc.ReflectUtil;
9593

9694
/**
9795
* Instances of the class {@code Class} represent classes and

src/java.base/share/classes/java/lang/reflect/Proxy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import jdk.internal.misc.VM;
5353
import jdk.internal.loader.ClassLoaderValue;
5454
import jdk.internal.vm.annotation.Stable;
55-
import sun.reflect.misc.ReflectUtil;
5655

5756
import static java.lang.invoke.MethodType.methodType;
5857
import static java.lang.module.ModuleDescriptor.Modifier.SYNTHETIC;
@@ -984,7 +983,7 @@ public static InvocationHandler getInvocationHandler(Object proxy)
984983
return ih;
985984
}
986985

987-
private static final String PROXY_PACKAGE_PREFIX = ReflectUtil.PROXY_PACKAGE;
986+
private static final String PROXY_PACKAGE_PREFIX = "com.sun.proxy";
988987

989988
/**
990989
* A cache of Method -> MethodHandle for default methods.

src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java

Lines changed: 4 additions & 10 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
@@ -29,7 +29,6 @@
2929
import java.lang.reflect.AnnotatedType;
3030
import java.lang.reflect.Constructor;
3131
import java.lang.reflect.GenericDeclaration;
32-
import java.lang.reflect.Member;
3332
import java.lang.reflect.Method;
3433
import java.lang.reflect.Type;
3534
import java.lang.reflect.TypeVariable;
@@ -41,7 +40,6 @@
4140
import sun.reflect.annotation.AnnotationType;
4241
import sun.reflect.generics.factory.GenericsFactory;
4342
import sun.reflect.generics.tree.FieldTypeSignature;
44-
import sun.reflect.misc.ReflectUtil;
4543

4644
/**
4745
* Implementation of {@code java.lang.reflect.TypeVariable} interface
@@ -135,13 +133,9 @@ public Type[] getBounds() {
135133
* @since 1.5
136134
*/
137135
public D getGenericDeclaration() {
138-
if (genericDeclaration instanceof Class<?> c)
139-
ReflectUtil.checkPackageAccess(c);
140-
else if ((genericDeclaration instanceof Method) ||
141-
(genericDeclaration instanceof Constructor))
142-
ReflectUtil.conservativeCheckMemberAccess((Member)genericDeclaration);
143-
else
144-
throw new AssertionError("Unexpected kind of GenericDeclaration");
136+
assert genericDeclaration instanceof Class<?> ||
137+
genericDeclaration instanceof Method ||
138+
genericDeclaration instanceof Constructor : "Unexpected kind of GenericDeclaration";
145139
return genericDeclaration;
146140
}
147141

src/java.base/share/classes/sun/reflect/misc/ConstructorUtil.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/java.base/share/classes/sun/reflect/misc/FieldUtil.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/java.base/share/classes/sun/reflect/misc/MethodUtil.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 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
@@ -79,15 +79,9 @@ private MethodUtil() {
7979

8080
public static Method getMethod(Class<?> cls, String name, Class<?>[] args)
8181
throws NoSuchMethodException {
82-
ReflectUtil.checkPackageAccess(cls);
8382
return cls.getMethod(name, args);
8483
}
8584

86-
public static Method[] getMethods(Class<?> cls) {
87-
ReflectUtil.checkPackageAccess(cls);
88-
return cls.getMethods();
89-
}
90-
9185
/*
9286
* Bounce through the trampoline.
9387
*/
@@ -140,7 +134,6 @@ protected synchronized Class<?> loadClass(String name, boolean resolve)
140134
throws ClassNotFoundException
141135
{
142136
// First, check if the class has already been loaded
143-
ReflectUtil.checkPackageAccess(name);
144137
Class<?> c = findLoadedClass(name);
145138
if (c == null) {
146139
try {

0 commit comments

Comments
 (0)