Skip to content

Commit

Permalink
Explicitly handle null arguments in System.setSecurityManager
Browse files Browse the repository at this point in the history
setSecurityManager should do nothing if the input argument is null and no
security manager has been established.

Before, this was being enforced implicitly. The implicit check no longer
works. There is error handling code and code to print a warning message,
which needs to avoided in the above "do nothing" scenario. So, an explicit
null check has been added to enforce the "no nothing" scenario.

Signed-off-by: Babneet Singh <[email protected]>
  • Loading branch information
babsingh committed Feb 3, 2022
1 parent bd6425f commit c0e4f3a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions jcl/src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,11 @@ 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) {
/*[MSG "K0B00", "The Security Manager is deprecated and will be removed in a future release"]*/
Expand Down

0 comments on commit c0e4f3a

Please sign in to comment.