1 /*
2 * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * 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.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
51 * objects.
52 *
53 * <p> The returned {@code ReflectionFactory} object should be carefully
54 * guarded by the caller, since it can be used to read and write private
55 * data and invoke private methods, as well as to load unverified bytecodes.
56 * It must never be passed to untrusted code.
57 *
58 * @return the ReflectionFactory
59 */
60 public static ReflectionFactory getReflectionFactory() {
61 return soleInstance;
62 }
63
64 /**
65 * Returns an accessible constructor capable of creating instances
66 * of the given class, initialized by the given constructor.
67 *
68 * @param cl the class to instantiate
69 * @param constructorToCall the constructor to call
70 * @return an accessible constructor
71 */
72 public Constructor<?> newConstructorForSerialization(Class<?> cl,
73 Constructor<?> constructorToCall)
74 {
75 return delegate.newConstructorForSerialization(cl,
76 constructorToCall);
77 }
78
79 /**
80 * Returns an accessible no-arg constructor for a class.
81 * The no-arg constructor is found searching the class and its supertypes.
82 *
83 * @param cl the class to instantiate
84 * @return a no-arg constructor for the class or {@code null} if
85 * the class or supertypes do not have a suitable no-arg constructor
86 */
87 public final Constructor<?> newConstructorForSerialization(Class<?> cl)
88 {
89 return delegate.newConstructorForSerialization(cl);
90 }
91
92 /**
93 * Returns an accessible no-arg constructor for an externalizable class to be
94 * initialized using a public no-argument constructor.
95 *
96 * @param cl the class to instantiate
97 * @return A no-arg constructor for the class; returns {@code null} if
98 * the class does not implement {@link java.io.Externalizable}
99 */
100 public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
101 return delegate.newConstructorForExternalization(cl);
102 }
103
104 /**
105 * Returns a direct MethodHandle for the {@code readObject} method on
|
1 /*
2 * Copyright (c) 2001, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * 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.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
51 * objects.
52 *
53 * <p> The returned {@code ReflectionFactory} object should be carefully
54 * guarded by the caller, since it can be used to read and write private
55 * data and invoke private methods, as well as to load unverified bytecodes.
56 * It must never be passed to untrusted code.
57 *
58 * @return the ReflectionFactory
59 */
60 public static ReflectionFactory getReflectionFactory() {
61 return soleInstance;
62 }
63
64 /**
65 * Returns an accessible constructor capable of creating instances
66 * of the given class, initialized by the given constructor.
67 *
68 * @param cl the class to instantiate
69 * @param constructorToCall the constructor to call
70 * @return an accessible constructor
71 * @throws UnsupportedOperationException if the constructor to call is
72 * not suitable for the class to instantiate, such as if the
73 * constructor is not of the given class or one of its supertypes,
74 * or this constructor would skip initialization of
75 * strictly-initialized fields
76 */
77 public Constructor<?> newConstructorForSerialization(Class<?> cl,
78 Constructor<?> constructorToCall)
79 {
80 return delegate.newConstructorForSerialization(cl,
81 constructorToCall);
82 }
83
84 /**
85 * Returns an accessible no-arg constructor for a class.
86 * The no-arg constructor is found searching the class and its supertypes,
87 * and must ensure that all strictly-initialized fields
88 * declared in the class and its supertypes are properly initialized.
89 *
90 * @param cl the class to instantiate
91 * @return a no-arg constructor for the class, or {@code null} if the
92 * class or supertypes do not have a suitable no-arg constructor
93 * or if the class is a value class
94 */
95 public final Constructor<?> newConstructorForSerialization(Class<?> cl)
96 {
97 return delegate.newConstructorForSerialization(cl);
98 }
99
100 /**
101 * Returns an accessible no-arg constructor for an externalizable class to be
102 * initialized using a public no-argument constructor.
103 *
104 * @param cl the class to instantiate
105 * @return A no-arg constructor for the class; returns {@code null} if
106 * the class does not implement {@link java.io.Externalizable}
107 */
108 public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
109 return delegate.newConstructorForExternalization(cl);
110 }
111
112 /**
113 * Returns a direct MethodHandle for the {@code readObject} method on
|