Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Many passive-tense sentences have been activated.

...

Code Block
bgColor#ffcccc
langjava
AccessController.doPrivileged(new PrivilegedAction<Void>() {
  public Void run() {
    // ...
  }
}, accessControlContext);

A When passed a null access control context means that the privileges would not be reduced the two-argument doPrivileged() method will fail to reduce the current privileges to those of the previously saved context. Consequently, this code may grant excess privileges if when the accessControlContext argument is null. If Programmers who intend to call AccessController.doPrivileged() is intended to be called with  with a null access control context , it should be explicitly passed pass the null constant.

Compliant Solution 

This compliant solution prevents granting of excess privileges from being granted by ensuring that accessControlContext is not non-null.

Code Block
bgColor#ccccff
langjava
if (accessControlContext == null) {
  throw new SecurityException("Missing AccessControlContext");
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
  public Void run() {
    // ...
  }
}, accessControlContext);

...