Skip to content

Commit 0610992

Browse files
author
Valerie Peng
committedMar 12, 2020
8238566: java.security.Provider$Service.supportsParameter() is racy
Use double-checked-locking pattern inside the hasKeyAttributes() method Reviewed-by: xuelei
1 parent 2eaeb20 commit 0610992

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed
 

‎src/java.base/share/classes/java/security/Provider.java

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1925,28 +1925,31 @@ private boolean hasKeyAttributes() {
19251925
Boolean b = hasKeyAttributes;
19261926
if (b == null) {
19271927
synchronized (this) {
1928-
String s;
1929-
s = getAttribute("SupportedKeyFormats");
1930-
if (s != null) {
1931-
supportedFormats = s.split("\\|");
1932-
}
1933-
s = getAttribute("SupportedKeyClasses");
1934-
if (s != null) {
1935-
String[] classNames = s.split("\\|");
1936-
List<Class<?>> classList =
1937-
new ArrayList<>(classNames.length);
1938-
for (String className : classNames) {
1939-
Class<?> clazz = getKeyClass(className);
1940-
if (clazz != null) {
1941-
classList.add(clazz);
1928+
b = hasKeyAttributes;
1929+
if (b == null) {
1930+
String s;
1931+
s = getAttribute("SupportedKeyFormats");
1932+
if (s != null) {
1933+
supportedFormats = s.split("\\|");
1934+
}
1935+
s = getAttribute("SupportedKeyClasses");
1936+
if (s != null) {
1937+
String[] classNames = s.split("\\|");
1938+
List<Class<?>> classList =
1939+
new ArrayList<>(classNames.length);
1940+
for (String className : classNames) {
1941+
Class<?> clazz = getKeyClass(className);
1942+
if (clazz != null) {
1943+
classList.add(clazz);
1944+
}
19421945
}
1946+
supportedClasses = classList.toArray(CLASS0);
19431947
}
1944-
supportedClasses = classList.toArray(CLASS0);
1948+
boolean bool = (supportedFormats != null)
1949+
|| (supportedClasses != null);
1950+
b = Boolean.valueOf(bool);
1951+
hasKeyAttributes = b;
19451952
}
1946-
boolean bool = (supportedFormats != null)
1947-
|| (supportedClasses != null);
1948-
b = Boolean.valueOf(bool);
1949-
hasKeyAttributes = b;
19501953
}
19511954
}
19521955
return b.booleanValue();

0 commit comments

Comments
 (0)
Please sign in to comment.