Skip to content

Commit

Permalink
8345565: Remove remaining SecurityManager motivated APIs from sun.ref…
Browse files Browse the repository at this point in the history
…lect.util

Reviewed-by: mullan, rriggs, liach
  • Loading branch information
Alan Bateman committed Dec 5, 2024
1 parent 97b8a09 commit 691e692
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 258 deletions.
16 changes: 0 additions & 16 deletions src/java.base/share/classes/java/io/ObjectInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import jdk.internal.event.DeserializationEvent;
import jdk.internal.misc.Unsafe;
import jdk.internal.util.ByteArray;
import sun.reflect.misc.ReflectUtil;

/**
* An ObjectInputStream deserializes primitive data and objects previously
Expand Down Expand Up @@ -1828,12 +1827,6 @@ private ObjectStreamClass readClassDesc(boolean unshared)
};
}

private boolean isCustomSubclass() {
// Return true if this class is a custom subclass of ObjectInputStream
return getClass().getClassLoader()
!= ObjectInputStream.class.getClassLoader();
}

/**
* Reads in and returns class descriptor for a dynamic proxy class. Sets
* passHandle to proxy class descriptor's assigned handle. If proxy class
Expand Down Expand Up @@ -1879,12 +1872,6 @@ private ObjectStreamClass readProxyDesc(boolean unshared)
} else if (!Proxy.isProxyClass(cl)) {
throw new InvalidClassException("Not a proxy");
} else {
// ReflectUtil.checkProxyPackageAccess makes a test
// equivalent to isCustomSubclass so there's no need
// to condition this call to isCustomSubclass == true here.
ReflectUtil.checkProxyPackageAccess(
getClass().getClassLoader(),
cl.getInterfaces());
// Filter the interfaces
for (Class<?> clazz : cl.getInterfaces()) {
filterCheck(clazz, -1);
Expand Down Expand Up @@ -1954,12 +1941,9 @@ private ObjectStreamClass readNonProxyDesc(boolean unshared)
Class<?> cl = null;
ClassNotFoundException resolveEx = null;
bin.setBlockDataMode(true);
final boolean checksRequired = isCustomSubclass();
try {
if ((cl = resolveClass(readDesc)) == null) {
resolveEx = new ClassNotFoundException("null class");
} else if (checksRequired) {
ReflectUtil.checkPackageAccess(cl);
}
} catch (ClassNotFoundException ex) {
resolveEx = ex;
Expand Down
13 changes: 0 additions & 13 deletions src/java.base/share/classes/java/io/ObjectOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import jdk.internal.util.ByteArray;
import jdk.internal.access.JavaLangAccess;
import jdk.internal.access.SharedSecrets;
import sun.reflect.misc.ReflectUtil;

import static jdk.internal.util.ModifiedUtf.putChar;
import static jdk.internal.util.ModifiedUtf.utfLen;
Expand Down Expand Up @@ -1170,12 +1169,6 @@ private void writeClassDesc(ObjectStreamClass desc, boolean unshared)
}
}

private boolean isCustomSubclass() {
// Return true if this class is a custom subclass of ObjectOutputStream
return getClass().getClassLoader()
!= ObjectOutputStream.class.getClassLoader();
}

/**
* Writes class descriptor representing a dynamic proxy class to stream.
*/
Expand All @@ -1193,9 +1186,6 @@ private void writeProxyDesc(ObjectStreamClass desc, boolean unshared)
}

bout.setBlockDataMode(true);
if (isCustomSubclass()) {
ReflectUtil.checkPackageAccess(cl);
}
annotateProxyClass(cl);
bout.setBlockDataMode(false);
bout.writeByte(TC_ENDBLOCKDATA);
Expand All @@ -1222,9 +1212,6 @@ private void writeNonProxyDesc(ObjectStreamClass desc, boolean unshared)

Class<?> cl = desc.forClass();
bout.setBlockDataMode(true);
if (cl != null && isCustomSubclass()) {
ReflectUtil.checkPackageAccess(cl);
}
annotateClass(cl);
bout.setBlockDataMode(false);
bout.writeByte(TC_ENDBLOCKDATA);
Expand Down
2 changes: 0 additions & 2 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -91,7 +90,6 @@
import sun.reflect.generics.repository.ConstructorRepository;
import sun.reflect.generics.scope.ClassScope;
import sun.reflect.annotation.*;
import sun.reflect.misc.ReflectUtil;

/**
* Instances of the class {@code Class} represent classes and
Expand Down
3 changes: 1 addition & 2 deletions src/java.base/share/classes/java/lang/reflect/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import jdk.internal.misc.VM;
import jdk.internal.loader.ClassLoaderValue;
import jdk.internal.vm.annotation.Stable;
import sun.reflect.misc.ReflectUtil;

import static java.lang.invoke.MethodType.methodType;
import static java.lang.module.ModuleDescriptor.Modifier.SYNTHETIC;
Expand Down Expand Up @@ -984,7 +983,7 @@ public static InvocationHandler getInvocationHandler(Object proxy)
return ih;
}

private static final String PROXY_PACKAGE_PREFIX = ReflectUtil.PROXY_PACKAGE;
private static final String PROXY_PACKAGE_PREFIX = "com.sun.proxy";

/**
* A cache of Method -> MethodHandle for default methods.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,7 +29,6 @@
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Constructor;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
Expand All @@ -41,7 +40,6 @@
import sun.reflect.annotation.AnnotationType;
import sun.reflect.generics.factory.GenericsFactory;
import sun.reflect.generics.tree.FieldTypeSignature;
import sun.reflect.misc.ReflectUtil;

/**
* Implementation of {@code java.lang.reflect.TypeVariable} interface
Expand Down Expand Up @@ -135,13 +133,9 @@ public Type[] getBounds() {
* @since 1.5
*/
public D getGenericDeclaration() {
if (genericDeclaration instanceof Class<?> c)
ReflectUtil.checkPackageAccess(c);
else if ((genericDeclaration instanceof Method) ||
(genericDeclaration instanceof Constructor))
ReflectUtil.conservativeCheckMemberAccess((Member)genericDeclaration);
else
throw new AssertionError("Unexpected kind of GenericDeclaration");
assert genericDeclaration instanceof Class<?> ||
genericDeclaration instanceof Method ||
genericDeclaration instanceof Constructor : "Unexpected kind of GenericDeclaration";
return genericDeclaration;
}

Expand Down
45 changes: 0 additions & 45 deletions src/java.base/share/classes/sun/reflect/misc/ConstructorUtil.java

This file was deleted.

48 changes: 0 additions & 48 deletions src/java.base/share/classes/sun/reflect/misc/FieldUtil.java

This file was deleted.

9 changes: 1 addition & 8 deletions src/java.base/share/classes/sun/reflect/misc/MethodUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -79,15 +79,9 @@ private MethodUtil() {

public static Method getMethod(Class<?> cls, String name, Class<?>[] args)
throws NoSuchMethodException {
ReflectUtil.checkPackageAccess(cls);
return cls.getMethod(name, args);
}

public static Method[] getMethods(Class<?> cls) {
ReflectUtil.checkPackageAccess(cls);
return cls.getMethods();
}

/*
* Bounce through the trampoline.
*/
Expand Down Expand Up @@ -140,7 +134,6 @@ protected synchronized Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
// First, check if the class has already been loaded
ReflectUtil.checkPackageAccess(name);
Class<?> c = findLoadedClass(name);
if (c == null) {
try {
Expand Down
Loading

1 comment on commit 691e692

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.