Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Put code in the method courtesy comment by Tim Halloran.

...

Code Block
bgColor#FFcccc
public Object publicLock = new Object();

private void doSomething() {
  synchronized(publicLock) { 
    // body
  }
}

It is possible for untrusted code to change the value of the lock object and foil all attempts to synchronize.

...

Code Block
bgColor#ccccff
private final Object privateLock = new Object();

private void doSomething() {
  synchronized(privateLock) { 
    // body
  }
}

Noncompliant Code Example (String constant)

...