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 be0d6a5790d..eda8eb2b476 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 @@ -344,23 +344,29 @@ private static void getProfileID(Properties props) { + selectedProfile); } String defaultMatch = null; + boolean profileExists = false; for (Object keyObject : props.keySet()) { if (keyObject instanceof String key) { - if (key.startsWith(potentialProfileID) && key.endsWith(".desc.default")) { - // Check if property is set to true. - if (Boolean.parseBoolean(props.getProperty(key))) { - // Check if multiple defaults exist and act accordingly. - if (defaultMatch == null) { - defaultMatch = key.split("\\.desc")[0]; - } else { - printStackTraceAndExit("Multiple default RestrictedSecurity" - + " profiles for " + selectedProfile); + if (key.startsWith(potentialProfileID)) { + profileExists = true; + if (key.endsWith(".desc.default")) { + // Check if property is set to true. + if (Boolean.parseBoolean(props.getProperty(key))) { + // Check if multiple defaults exist and act accordingly. + if (defaultMatch == null) { + defaultMatch = key.substring(0, key.length() - ".desc.default".length()); + } else { + printStackTraceAndExit("Multiple default RestrictedSecurity" + + " profiles for " + selectedProfile); + } } } } } } - if (defaultMatch == null) { + if (!profileExists) { + printStackTraceAndExit(selectedProfile + " is not present in the java.security file."); + } else if (defaultMatch == null) { printStackTraceAndExit("No default RestrictedSecurity profile was found for " + selectedProfile); } else {