-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathReadOnlyContainer.qhelp
More file actions
39 lines (30 loc) · 973 Bytes
/
ReadOnlyContainer.qhelp
File metadata and controls
39 lines (30 loc) · 973 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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>
Code that queries the contents of a collection (such as <code>ContainsKey</code>
or <code>Count</code>) is invoked on an object that is known to be empty. Such queries
do not return interesting results, and may indicate missing code or a logic error.
</p>
</overview>
<recommendation>
<p>
Either remove the collection if it is unnecessary, or ensure that it contains the
correct data.
</p>
</recommendation>
<example>
<p>
The following example code is supposed to return the name of the day, but does not work
because the collection <code>daysOfWeek</code> is never populated. When this code is run, an
<code>ArgumentOutOfRangeException</code> exception is thrown.
</p>
<sample src="ReadOnlyContainer.cs" />
<p>
This problem is fixed by populating the variable <code>daysOfWeek</code> with the correct data.
</p>
<sample src="ReadOnlyContainerFix.cs" />
</example>
</qhelp>