Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

One technique for preventing this vulnerability is the private lock object idiom [Bloch 2001]. This idiom uses the intrinsic lock associated with the instance of a private final java.lang.Object declared within the class instead of the intrinsic lock of the object itself. This idiom requires the use of synchronized blocks within the class’s methods rather than the use of synchronized methods. Lock contention between the class’s methods and those of a hostile class becomes impossible because the hostile class cannot access the private final lock object.

...

This noncompliant code example also violates rule OBJ01-J. Declare data members as private and provide accessible wrapper methodsLimit accessibility of fields.

Compliant Solution (Private Final Lock Object)

...

MITRE CWE

CWE-412. Unrestricted externally accessible lock

 

CWE-413. Improper resource locking

Bibliography

[Bloch 2001]

Item 52. Document Thread Safety

...

08. Locking (LCK)      08. Locking (LCK)Image Added      Image Added