8238566: java.security.Provider$Service.supportsParameter() is racy

Use double-checked-locking pattern inside the hasKeyAttributes() method

Reviewed-by: xuelei
This commit is contained in:
Valerie Peng 2020-03-12 22:11:49 +00:00
parent 2eaeb20697
commit 0610992a8f

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1925,28 +1925,31 @@ public abstract class Provider extends Properties {
Boolean b = hasKeyAttributes;
if (b == null) {
synchronized (this) {
String s;
s = getAttribute("SupportedKeyFormats");
if (s != null) {
supportedFormats = s.split("\\|");
}
s = getAttribute("SupportedKeyClasses");
if (s != null) {
String[] classNames = s.split("\\|");
List<Class<?>> classList =
new ArrayList<>(classNames.length);
for (String className : classNames) {
Class<?> clazz = getKeyClass(className);
if (clazz != null) {
classList.add(clazz);
}
b = hasKeyAttributes;
if (b == null) {
String s;
s = getAttribute("SupportedKeyFormats");
if (s != null) {
supportedFormats = s.split("\\|");
}
supportedClasses = classList.toArray(CLASS0);
s = getAttribute("SupportedKeyClasses");
if (s != null) {
String[] classNames = s.split("\\|");
List<Class<?>> classList =
new ArrayList<>(classNames.length);
for (String className : classNames) {
Class<?> clazz = getKeyClass(className);
if (clazz != null) {
classList.add(clazz);
}
}
supportedClasses = classList.toArray(CLASS0);
}
boolean bool = (supportedFormats != null)
|| (supportedClasses != null);
b = Boolean.valueOf(bool);
hasKeyAttributes = b;
}
boolean bool = (supportedFormats != null)
|| (supportedClasses != null);
b = Boolean.valueOf(bool);
hasKeyAttributes = b;
}
}
return b.booleanValue();