RFR: JDK-8211121: Remove sun.reflect.ReflectionFactory::newInstanceForSerialization
Lance Andersen
lance.andersen at oracle.com
Wed Sep 26 17:01:55 UTC 2018
> On Sep 26, 2018, at 1:19 AM, mandy chung <mandy.chung at oracle.com> wrote:
>
> The imports statement of jdk.internal.misc.SharedSecrets and JavaSecurityAccess can be removed.
Thank you Mandy, thought I clicked to remove unused imports in netbeans but guess I did not. Here is the revised diff
————
$ hg diff src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java
diff -r e1368526699d src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java
--- a/src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java Wed Sep 26 06:26:54 2018 +0800
+++ b/src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java Wed Sep 26 12:41:11 2018 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2018, 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
@@ -29,14 +29,9 @@
import java.lang.invoke.MethodHandle;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.Permission;
-import java.security.ProtectionDomain;
import java.security.PrivilegedAction;
-import jdk.internal.misc.SharedSecrets;
-import jdk.internal.misc.JavaSecurityAccess;
/**
* ReflectionFactory supports custom serialization.
@@ -145,66 +140,6 @@
}
/**
- * Invokes the supplied constructor, adding the provided protection domains
- * to the invocation stack before invoking {@code Constructor::newInstance}.
- * If no {@linkplain System#getSecurityManager() security manager} is present,
- * or no domains are provided, then this method simply calls
- * {@code cons.newInstance()}. Otherwise, it invokes the provided constructor
- * with privileges at the intersection of the current context and the provided
- * protection domains.
- *
- * @param cons A constructor obtained from {@code
- * newConstructorForSerialization} or {@code
- * newConstructorForExternalization}.
- * @param domains An array of protection domains that limit the privileges
- * with which the constructor is invoked. Can be {@code null}
- * or empty, in which case privileges are only limited by the
- * {@linkplain AccessController#getContext() current context}.
- *
- * @return A new object built from the provided constructor.
- *
- * @throws NullPointerException if {@code cons} is {@code null}.
- * @throws InstantiationException if thrown by {@code cons.newInstance()}.
- * @throws InvocationTargetException if thrown by {@code cons.newInstance()}.
- * @throws IllegalAccessException if thrown by {@code cons.newInstance()}.
- */
- public final Object newInstanceForSerialization(Constructor<?> cons,
- ProtectionDomain[] domains)
- throws InstantiationException, InvocationTargetException, IllegalAccessException
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm == null || domains == null || domains.length == 0) {
- return cons.newInstance();
- } else {
- JavaSecurityAccess jsa = SharedSecrets.getJavaSecurityAccess();
- PrivilegedAction<?> pea = () -> {
- try {
- return cons.newInstance();
- } catch (InstantiationException
- | InvocationTargetException
- | IllegalAccessException x) {
- throw new UndeclaredThrowableException(x);
- }
- }; // Can't use PrivilegedExceptionAction with jsa
- try {
- return jsa.doIntersectionPrivilege(pea,
- AccessController.getContext(),
- new AccessControlContext(domains));
- } catch (UndeclaredThrowableException x) {
- Throwable cause = x.getCause();
- if (cause instanceof InstantiationException)
- throw (InstantiationException) cause;
- if (cause instanceof InvocationTargetException)
- throw (InvocationTargetException) cause;
- if (cause instanceof IllegalAccessException)
- throw (IllegalAccessException) cause;
- // not supposed to happen
- throw x;
- }
- }
- }
-
- /**
* Returns a direct MethodHandle for the {@code readObjectNoData} method on
* a Serializable class.
* The first argument of {@link MethodHandle#invoke} is the serializable
—————
Local build went fine. Mach5 is running again for an additional sanity check
Best
Lance
>
> Otherwise looks fine.
>
> Mandy
>
> On 9/25/18 4:10 PM, Lance Andersen wrote:
>> Hi all:
>>
>> JDK-8211121 removes sun.reflect.ReflectionFactory::newInstanceForSerialization which was only used by the java.corba module. It was missed as part of the initial removal of the Java EE modules.
>>
>> The diff for the change:
>> —————
>> s$ hg diff src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java
>> diff -r a6bdb6d5f167 src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java
>> --- a/src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java Tue Sep 25 11:31:55 2018 -0700
>> +++ b/src/jdk.unsupported/share/classes/sun/reflect/ReflectionFactory.java Tue Sep 25 17:32:48 2018 -0400
>> @@ -145,66 +145,6 @@
>> }
>>
>> /**
>> - * Invokes the supplied constructor, adding the provided protection domains
>> - * to the invocation stack before invoking {@code Constructor::newInstance}.
>> - * If no {@linkplain System#getSecurityManager() security manager} is present,
>> - * or no domains are provided, then this method simply calls
>> - * {@code cons.newInstance()}. Otherwise, it invokes the provided constructor
>> - * with privileges at the intersection of the current context and the provided
>> - * protection domains.
>> - *
>> - * @param cons A constructor obtained from {@code
>> - * newConstructorForSerialization} or {@code
>> - * newConstructorForExternalization}.
>> - * @param domains An array of protection domains that limit the privileges
>> - * with which the constructor is invoked. Can be {@code null}
>> - * or empty, in which case privileges are only limited by the
>> - * {@linkplain AccessController#getContext() current context}.
>> - *
>> - * @return A new object built from the provided constructor.
>> - *
>> - * @throws NullPointerException if {@code cons} is {@code null}.
>> - * @throws InstantiationException if thrown by {@code cons.newInstance()}.
>> - * @throws InvocationTargetException if thrown by {@code cons.newInstance()}.
>> - * @throws IllegalAccessException if thrown by {@code cons.newInstance()}.
>> - */
>> - public final Object newInstanceForSerialization(Constructor<?> cons,
>> - ProtectionDomain[] domains)
>> - throws InstantiationException, InvocationTargetException, IllegalAccessException
>> - {
>> - SecurityManager sm = System.getSecurityManager();
>> - if (sm == null || domains == null || domains.length == 0) {
>> - return cons.newInstance();
>> - } else {
>> - JavaSecurityAccess jsa = SharedSecrets.getJavaSecurityAccess();
>> - PrivilegedAction<?> pea = () -> {
>> - try {
>> - return cons.newInstance();
>> - } catch (InstantiationException
>> - | InvocationTargetException
>> - | IllegalAccessException x) {
>> - throw new UndeclaredThrowableException(x);
>> - }
>> - }; // Can't use PrivilegedExceptionAction with jsa
>> - try {
>> - return jsa.doIntersectionPrivilege(pea,
>> - AccessController.getContext(),
>> - new AccessControlContext(domains));
>> - } catch (UndeclaredThrowableException x) {
>> - Throwable cause = x.getCause();
>> - if (cause instanceof InstantiationException)
>> - throw (InstantiationException) cause;
>> - if (cause instanceof InvocationTargetException)
>> - throw (InvocationTargetException) cause;
>> - if (cause instanceof IllegalAccessException)
>> - throw (IllegalAccessException) cause;
>> - // not supposed to happen
>> - throw x;
>> - }
>> - }
>> - }
>> -
>> - /**
>> * Returns a direct MethodHandle for the {@code readObjectNoData} method on
>> * a Serializable class.
>> * The first argument of {@link MethodHandle#invoke} is the serializable
>> ——————
>>
>>
>>
>> Best
>> Lance
>> <http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif>
>> <http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif>
>> <http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif>Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
>> Oracle Java Engineering
>> 1 Network Drive
>> Burlington, MA 01803
>> Lance.Andersen at oracle.com <mailto:Lance.Andersen at oracle.com> <mailto:Lance.Andersen at oracle.com> <mailto:Lance.Andersen at oracle.com>
>>
>>
>>
>
<http://oracle.com/us/design/oracle-email-sig-198324.gif>
<http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif>
<http://oracle.com/us/design/oracle-email-sig-198324.gif>Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com <mailto:Lance.Andersen at oracle.com>
More information about the core-libs-dev
mailing list