Skip to content

Commit 905b763

Browse files
liachMandy Chung
authored andcommitted
8261404: Class.getReflectionFactory() is not thread-safe
Reviewed-by: rriggs, mchung
1 parent 022e4f0 commit 905b763

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/java.base/share/classes/java/lang/Class.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,12 +3820,13 @@ public boolean isRecord() {
38203820
// Fetches the factory for reflective objects
38213821
@SuppressWarnings("removal")
38223822
private static ReflectionFactory getReflectionFactory() {
3823-
if (reflectionFactory == null) {
3824-
reflectionFactory =
3825-
java.security.AccessController.doPrivileged
3826-
(new ReflectionFactory.GetReflectionFactoryAction());
3823+
var factory = reflectionFactory;
3824+
if (factory != null) {
3825+
return factory;
38273826
}
3828-
return reflectionFactory;
3827+
return reflectionFactory =
3828+
java.security.AccessController.doPrivileged
3829+
(new ReflectionFactory.GetReflectionFactoryAction());
38293830
}
38303831
private static ReflectionFactory reflectionFactory;
38313832

0 commit comments

Comments
 (0)