Versions Compared

Key

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

...

Operations on objects of type AtomicInteger suffer from the same overflow issues as other integer types. The solutions are generally similar to the solutions already presented; however, concurrency issues add additional complications. First, potential issues with time-of-check, time-of-use (TOCTOU) must be avoided; see rule VNA02-J. Ensure that compound operations on shared variables are atomic for more information. Second, use of an AtomicInteger creates happens-before relationships between the various threads that access it. Consequently, changes to the number of accesses or order of accesses can alter the execution of the overall program. In such cases, you must either choose to accept the altered execution or carefully craft your implementation to preserve the exact number of accesses and order of accesses to the AtomicInteger.

...

Wiki Markup
The two arguments to the {{compareAndSet()}} method are the expected value of the variable when the method is invoked and the intended new value. The variable's value is updated only when the current value and the expected value are equal \[[API 2006|AA. Bibliography#API 06]\]. Refer to rule [VNA02-J. Ensure that compound operations on shared variables are atomic] for more details.

Exceptions

...

NUM00-EX1: Prevention of integer overflow is unnecessary for numeric fields that undergo bitwise operations and not arithmetic operations. See rule NUM01-J. Avoid performing bitwise and arithmetic operations on the same data for more information.

Risk Assessment

...

The CERT C Secure Coding Standard

INT32-C. Ensure that operations on signed integers do not result in overflow

The CERT C++ Secure Coding Standard

INT32-CPP. Ensure that operations on signed integers do not result in overflow

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="02eb7b681fb967f2-aae37c6c-4a1c49a5-be458240-fbd6cf33739f811262c017ff"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

Wrap-around Error [XYY]

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

MITRE CWE

CWE-682. Incorrect calculation

 

CWE-190. Integer overflow or wraparound

 

CWE-191. Integer underflow (wrap or wraparound)

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="575a647eb87f4ea7-86c21660-41a74a05-b9f9b848-b663659c0170744d9daea812"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

Class [AtomicInteger

http://download.oracle.com/javase/6/docs/api/java/util/concurrent/atomic/AtomicInteger.html]

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ff174d83dbcf9a66-815a9f98-42bd42bc-bc348f34-ba4b5ecbce9930b1692fa6ff"><ac:plain-text-body><![CDATA[

[[Bloch 2005

AA. Bibliography#Bloch 05]]

Puzzle 27. Shifty i's

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="a234218292b8008d-063e81c5-4c694c57-934f98c4-56f69b1e6aabebf0c0f98896"><ac:plain-text-body><![CDATA[

[[JLS 2005

AA. Bibliography#JLS 05]]

[§4.2.2, Integer Operations

http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.2]

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

 

§15.22, Bitwise and Logical Operators

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="b0b044a8891d8e92-d09289d5-4bda48f3-a45ab766-ba9c0d0cbf24ed1e2b4dc31a"><ac:plain-text-body><![CDATA[

[[Seacord 2005

AA. Bibliography#Seacord 05]]

Chapter 5, Integers

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

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ca6d14cbbfc65ebb-f643cd51-43194bf0-890a9577-1f291cb0934461c90d1810be"><ac:plain-text-body><![CDATA[

[[Tutorials 2008

AA. Bibliography#Tutorials 08]]

Primitive Data Types

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

...