RFR: 8261404: Class.getReflectionFactory() is not thread-safe
Roger Riggs
rriggs at openjdk.java.net
Thu Dec 16 21:34:58 UTC 2021
On Thu, 16 Dec 2021 21:04:58 GMT, liach <duke at openjdk.java.net> wrote:
> Simply changes this to only read the static field once to prevent `null` on second read.
src/java.base/share/classes/java/lang/Class.java line 3828:
> 3826: java.security.AccessController.doPrivileged
> 3827: (new ReflectionFactory.GetReflectionFactoryAction());
> 3828: }
p.s. If using an early return, I'd have it return early in the case reflectionFactory was not-null.
then fall through to compute and assign the factory and return it.
var factory = reflectionFactory;
if (factory != null) {
return factory;
}
return reflectionFactory =
java.security.AccessController.doPrivileged
(new ReflectionFactory.GetReflectionFactoryAction());
-------------
PR: https://git.openjdk.java.net/jdk/pull/6870
More information about the core-libs-dev
mailing list