Java Reference
In-Depth Information
array[1] = 4435;
array[2] = 0042;
// ...
}
It appears that the third element in array is intended to hold the decimal value 42.
However, the decimal value 34 (corresponding to the octal value 42) gets assigned.
Compliant Solution
When integer literals are intended to represent a decimal value, avoid padding with lead-
ing zeros. Use another technique instead, such as padding with whitespace, to preserve
digit alignment.
Click here to view code image
int[] array = new int[3];
void exampleFunction() {
array[0] = 2719;
array[1] = 4435;
array[2] =
42;
// ...
}
Applicability
Failing to use visually distinct identifiers could result in the use of the wrong identifier
and lead to unexpected program behavior.
Heuristic detection of identifiers with visually similar names is straightforward. Con-
fusing a lowercase letter l with a digit 1 when indicating that an integer denotation is a
long value can result in incorrect computations. Automated detection is trivial.
Mixing decimal and octal values can result in improper initialization or assignment.
Detection of integer literals that have a leading zero is trivial. However, determining
whether the programmer intended to use an octal literal or a decimal literal is infeasible.
Accordingly, sound automated detection is also infeasible. Heuristic checks may be use-
ful.
Search WWH ::




Custom Search