Skip to content

Commit

Permalink
Correctly throw UOE from setSecurityManager
Browse files Browse the repository at this point in the history
In some cases, warning messages are no longer being printed when the input
argument is null. Revising the fix in eclipse-openj9#14329 to correctly throw
UnsupportedOperationException (UOE) in case of a null input argument when the
security manager is disallowed.

When the security manager is not allowed to be set dynamically, return if the
input argument is null. UnsupportedOperationException should only be thrown for
a non-null input argument.

Fixes: eclipse-openj9#14445

Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Feb 7, 2022
1 parent ecc33af commit b457ee8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions jcl/src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -1118,13 +1118,15 @@ public static void setSecurityManager(final SecurityManager s) {
@SuppressWarnings("removal")
final SecurityManager currentSecurity = security;

if ((currentSecurity == null) && (s == null)) {
/* Return if the input argument is null and no security manager has been established. */
return;
}

/*[IF JAVA_SPEC_VERSION > 11]*/
if (throwUOEFromSetSM) {
/* The security manager is not allowed to be set dynamically. Return if the
* argument is null. UnsupportedOperationException should only be thrown for
* a non-null argument.
*/
if (s == null) {
return;
}
/*[MSG "K0B00", "The Security Manager is deprecated and will be removed in a future release"]*/
throw new UnsupportedOperationException(com.ibm.oti.util.Msg.getString("K0B00")); //$NON-NLS-1$
}
Expand Down

0 comments on commit b457ee8

Please sign in to comment.