Skip to content

Commit a3ed56a

Browse files
committed
Add the error message when the profile does not exist
In Restricted Security Mode, add the error message when the profile name is used without the version part in "-Dsemeru.customprofile=", and the specified profile does not exist in the java.security file. Signed-off-by: Tao Liu <[email protected]>
1 parent 5a723c0 commit a3ed56a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

closed/src/java.base/share/classes/openj9/internal/security/RestrictedSecurity.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -344,23 +344,29 @@ private static void getProfileID(Properties props) {
344344
+ selectedProfile);
345345
}
346346
String defaultMatch = null;
347+
boolean profileExists = false;
347348
for (Object keyObject : props.keySet()) {
348349
if (keyObject instanceof String key) {
349-
if (key.startsWith(potentialProfileID) && key.endsWith(".desc.default")) {
350-
// Check if property is set to true.
351-
if (Boolean.parseBoolean(props.getProperty(key))) {
352-
// Check if multiple defaults exist and act accordingly.
353-
if (defaultMatch == null) {
354-
defaultMatch = key.split("\\.desc")[0];
355-
} else {
356-
printStackTraceAndExit("Multiple default RestrictedSecurity"
357-
+ " profiles for " + selectedProfile);
350+
if (key.startsWith(potentialProfileID)) {
351+
profileExists = true;
352+
if (key.endsWith(".desc.default")) {
353+
// Check if property is set to true.
354+
if (Boolean.parseBoolean(props.getProperty(key))) {
355+
// Check if multiple defaults exist and act accordingly.
356+
if (defaultMatch == null) {
357+
defaultMatch = key.substring(0, key.length() - ".desc.default".length());
358+
} else {
359+
printStackTraceAndExit("Multiple default RestrictedSecurity"
360+
+ " profiles for " + selectedProfile);
361+
}
358362
}
359363
}
360364
}
361365
}
362366
}
363-
if (defaultMatch == null) {
367+
if (!profileExists) {
368+
printStackTraceAndExit(selectedProfile + " is not present in the java.security file.");
369+
} else if (defaultMatch == null) {
364370
printStackTraceAndExit("No default RestrictedSecurity profile was found for "
365371
+ selectedProfile);
366372
} else {

0 commit comments

Comments
 (0)