...
In this noncompliant code example, multiple threads can invoke the setValues()
method to set the a
and b
fields. Because this class fails to test for integer overflow, users of the Adder
class must ensure that the arguments to the setValues()
method can be added without overflow. (For more information, see rule NUM16 NUM00-J. Detect or prevent integer overflow.)
Code Block | ||
---|---|---|
| ||
final class Adder { private int a; private int b; public int getSum() { return a + b; } public void setValues(int a, int b) { this.a = a; this.b = b; } } |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="db03b75ddcc4336c-c69700db-43ba4019-8a289452-8c96aa70fa758278a3f46a0f"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | Class AtomicInteger | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2a11e11312a21a51-fa04cde6-40914e71-989cbffc-f060a5cc39b4e560c46bc7f8"><ac:plain-text-body><![CDATA[ | [[Bloch 2008 | AA. Bibliography#Bloch 08]] | Item 66: Synchronize access to shared mutable data | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d79b8ad263ec8b1a-24d75cc1-4e894906-864b9726-02a744baa481fc3dfa1acfb8"><ac:plain-text-body><![CDATA[ | [[Goetz 2006 | AA. Bibliography#Goetz 06]] | 2.3. "Locking" | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="fbfce6bc26d67df0-ba0e605d-4ea04c26-bc239c6d-decb07542db6e57657d8814b"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [Chapter 17 Threads and Locks | http://java.sun.com/docs/books/jls/third_edition/html/memory.html], ]]></ac:plain-text-body></ac:structured-macro> | |
| Section 17.4.5 Happens-Before Order | ||||
| Section 17.4.3 Programs and Program Order | ||||
| Section 17.4.8 Executions and Causality Requirements | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="078377f148768c1b-dcbf878a-4569492a-ab038c26-4d68f77dbe802f96fbb2a13d"><ac:plain-text-body><![CDATA[ | [[Lea 2000 | AA. Bibliography#Lea 00]] | Section 2.2.7 The Java Memory Model | ]]></ac:plain-text-body></ac:structured-macro> | |
| Section 2.1.1.1 Objects and Locks | ||||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0a2f5b175b23956c-b39900fb-42954881-b69a9b7e-f1512bdd0d1c311c6dfb6737"><ac:plain-text-body><![CDATA[ | [[Tutorials 2008 | AA. Bibliography#Tutorials 08]] | [Java Concurrency Tutorial | http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] | ]]></ac:plain-text-body></ac:structured-macro> |
...