Versions Compared

Key

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

Methods that can both can modify a static field and also can be invoked from untrusted code must synchronize access to the static field. Even when client-side locking is a specified requirement of the method, untrusted clients can fail to synchronize (whether inadvertently or maliciously). Because the static field is shared by all clients, untrusted clients may violate the contract by failing to provide suitable locking.

...

This class definition complies with rule VNA02-J. Ensure that compound operations on shared variables are atomic, which applies only applies to classes that promise thread-safety. However, this class has a mutable static counter field that is modified by the publicly accessible incrementCounter() method. Consequently, this class cannot be used securely by trusted client code , because untrusted code can purposely fail to externally synchronize access to the field.

...

This compliant solution uses a static private final lock to protect the counter field and , consequently , lacks any dependence on external synchronization. This solution also complies with rule LCK00-J. Use private final lock objects to synchronize classes that may interact with untrusted code.

...

Failure to internally synchronize access to static fields that can be modified by untrusted code risks incorrect synchronization , because the author of the untrusted code can ignore the synchronization policy (whether inadvertently or maliciously).

...

Related Guidelines

MITRE CWE

CWE-820, ". Missing Synchronization" synchronization

Bibliography

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="36956f07318fdd9f-06898be0-41a548d7-913a907d-676f0807c739a983d9ff6e89"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

 

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5f666dd6da990406-4768b90b-4d574006-85ca9982-350d501899455b2bf850c08c"><ac:plain-text-body><![CDATA[

[[Bloch 2008

AA. Bibliography#Bloch 08]]

Item 67: ". Avoid excessive synchronization "

]]></ac:plain-text-body></ac:structured-macro>

...