From da716ffc440e9198aed34f801357188a1edbd8ec Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 23 Sep 2024 15:03:04 -0400 Subject: [PATCH] update according to code review --- .../internal/security/RestrictedSecurity.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java b/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java index ade69839ebb..14984644ccb 100644 --- a/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java +++ b/closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java @@ -39,7 +39,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; @@ -995,8 +994,8 @@ private static final class ProfileParser { // The java.security properties. private final Properties securityProps; - private LinkedList profileCheckPropertyNames; - private LinkedList profileCheckProviderNames; + private final Set profileCheckPropertyNames; + private final Set profileCheckProviderNames; /** * @@ -1020,8 +1019,8 @@ private ProfileParser(String id, Properties props) { parsedProfiles = new HashSet<>(); - profileCheckPropertyNames = new LinkedList<>(); - profileCheckProviderNames = new LinkedList<>(); + profileCheckPropertyNames = new HashSet<>(); + profileCheckProviderNames = new HashSet<>(); // Initialize the properties. init(profileID); @@ -1051,13 +1050,14 @@ private void init(String profileID) { loadProfileCheck(profileID); - String potentialExtendsProfileID = parseProperty(securityProps.getProperty(profileID + ".extends")); + String profileExtendsKeyword = profileID + ".extends"; + String potentialExtendsProfileID = parseProperty(securityProps.getProperty(profileExtendsKeyword)); if (potentialExtendsProfileID != null) { // If profile extends another profile. if (debug != null) { debug.println("\t'" + profileID + "' extends '" + potentialExtendsProfileID + "'."); } - profileCheckPropertyNames.remove(profileID + ".extends"); + profileCheckPropertyNames.remove(profileExtendsKeyword); // Check if extended profile exists. String extendsProfileID = null; @@ -1730,10 +1730,12 @@ private void loadProfileCheck(String profileID) { Enumeration pNames = securityProps.propertyNames(); while (pNames.hasMoreElements()) { String name = (String) pNames.nextElement(); - if (name.startsWith(profileID + '.') && name.contains(".jce.provider.")) { - profileCheckProviderNames.add(name); - } else if (name.startsWith(profileID + '.')) { - profileCheckPropertyNames.add(name); + if (name.startsWith(profileID + '.')) { + if (name.contains(".jce.provider.")) { + profileCheckProviderNames.add(name); + } else { + profileCheckPropertyNames.add(name); + } } } } @@ -1741,14 +1743,14 @@ private void loadProfileCheck(String profileID) { private void checkProfileCheck(String profileID) { if (!profileCheckProviderNames.isEmpty()) { printStackTraceAndExit( - "The order of providers in profile " + profileID - + " (or its base profile) is incorrect."); + "The order numbers of providers in profile " + profileID + + " (or its base profile) are not consecutive."); } if (!profileCheckPropertyNames.isEmpty()) { printStackTraceAndExit( - "The property name: " + profileCheckPropertyNames.toString() + "One or more property names: " + profileCheckPropertyNames.toString() + " in profile " + profileID - + " may be misspelled."); + + " are misspelled."); } } }