On 04/28/2016 09:06 PM, Jason Mehrens wrote:
Hi Peter,
As mentioned, Class.newInstance() has a special cache for constructor
and caller that speeds up repeated invocations from the same caller by
skipping access checks.
I'm sure I'm missing something obvious related to performance or security but,
couldn't the exact same 'cachedConstructor' field be used for caching
Class.getConstructor(new Class[0]) as long as a constructor copy is returned?
That way the recommended workaround is near the same performance.
This would only speed up the lookup part (optimization for looking up
no-arg constructor - perhaps this could be a special field in
Class.ReflectionData), but returning a copy would force re-evaluation of
access checks which can now be skipped if the caller remains the same in
consecutive invocations to Class.newInstance().
Regards, Peter