RFR: 8332586: Avoid cloning empty arrays in java.lang.reflect.{Method,Constructor}

jengebr duke at openjdk.org
Thu May 30 19:30:14 UTC 2024


On Wed, 22 May 2024 10:27:16 GMT, Chen Liang <liach at openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java line 249:
>> 
>>> 247:      * the original can safely be reused.
>>> 248:      */
>>> 249:     public Class<?>[] copyClasses(Class<?>[] classes) {
>> 
>> There is no need to make this utility method non-static. This would also obviate the need for having an instance of `ReflectionFactory` to access it. 
>> 
>> Additionally, at the risk of more bikeshedding, I think this utility method is better suited in `AccessibleObject` base class, with package-private visibility. Putting the util methods in `ReflectionFactory` erodes this comment a bit:
>> 
>> 
>>     <P> The methods in this class are extremely unsafe and can cause
>>     subversion of both the language and the verifier. For this reason,
>>     they are all instance methods, and access to the constructor of
>>     this factory is guarded by a security check, in similar style to
>>     {@link jdk.internal.misc.Unsafe}. </P>
>
> Can't this be used by class cloning interfaces too?

@liach I see such an opportunity in `Proxy.getProxyConstructor`, is that what you have in mind?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19327#discussion_r1609907464


More information about the core-libs-dev mailing list