-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathArrayIndexOutOfBounds.qhelp
More file actions
42 lines (34 loc) · 958 Bytes
/
ArrayIndexOutOfBounds.qhelp
File metadata and controls
42 lines (34 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
When accessing an array element, one must ensure that the index is less than
the length of the array. Using an index that is greater than or equal to the
array length causes an <code>ArrayIndexOutOfBoundsException</code>.
</p>
</overview>
<recommendation>
<p>
Ensure that the index is less than the array length.
</p>
</recommendation>
<example>
<p>
The following example causes an <code>ArrayIndexOutOfBoundsException</code> in
the final loop iteration.
</p>
<sample src="ArrayIndexOutOfBoundsBad.java" />
<p>
The condition should be changed as follows to correctly guard the array access.
</p>
<sample src="ArrayIndexOutOfBoundsGood.java" />
</example>
<references>
<li>
The Java API Specification:
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/ArrayIndexOutOfBoundsException.html">ArrayIndexOutOfBoundsException</a>.
</li>
</references>
</qhelp>