Skip to content

Commit 5464248

Browse files
committed
Use a static synchronized method for allPermissionsPD
Since allPermissionsPD is a static field, a static synchronized method locks on Class.class, which is the correct approach. Fixes: eclipse-openj9#20351 Signed-off-by: Babneet Singh <[email protected]>
1 parent f952f8d commit 5464248

File tree

1 file changed

+5
-7
lines changed
  • jcl/src/java.base/share/classes/java/lang

1 file changed

+5
-7
lines changed

Diff for: jcl/src/java.base/share/classes/java/lang/Class.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -2491,17 +2491,15 @@ ProtectionDomain getProtectionDomainInternal() {
24912491
return allPermissionsPD;
24922492
}
24932493

2494-
private void allocateAllPermissionsPD() {
2494+
private static synchronized void allocateAllPermissionsPD() {
24952495
/* Synchronization to ensure safe initialization and safe publication of
24962496
* allPermissionsPD. This addresses the locking contention on allPermissionsPD
24972497
* in getProtectionDomain().
24982498
*/
2499-
synchronized(this) {
2500-
if (allPermissionsPD == null) {
2501-
Permissions collection = new Permissions();
2502-
collection.add(SecurityConstants.ALL_PERMISSION);
2503-
allPermissionsPD = new ProtectionDomain(null, collection);
2504-
}
2499+
if (allPermissionsPD == null) {
2500+
Permissions collection = new Permissions();
2501+
collection.add(SecurityConstants.ALL_PERMISSION);
2502+
allPermissionsPD = new ProtectionDomain(null, collection);
25052503
}
25062504
}
25072505

0 commit comments

Comments
 (0)