typetools / typetools/checker-framework
Index Checker cannot estimate value of a variable (which is declared outside the loop) inside the loop
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Consider the following code:
class tryit{
public static void check_it(int[] a) {
int index = 0;
for(int x = 0 ; x < a.length ; x++){
a[index++] = 0;
}
}
}
Run it by typing in the terminal:
javac -processor index tryit.java
Output:
tryit.java:6: error: [array.access.unsafe.high.range] Potentially unsafe array access: the index could be larger than the array's bound
a[index++] = 0;
^
index type found: @IntRange(from=-2147483648, to=9223372036854775807) int
array type found: @UnknownVal int @UnknownVal []
required : index of type @IndexFor("a") or @LTLengthOf("a"), or array of type @MinLen(-9223372036854775808)
1 error
Firstly, the checker is imprecise in estimating the value of index inside the loop.
Second, the error message @MinLen(-9223372036854775808) seem absurd.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report using tryit.java and javac -processor index tryit.java, then trace the Index Checker handling of the variable declared before the loop. Investigate why the loop does not refine index and why the diagnostic reports @MinLen(-9223372036854775808). Done means the example is analyzed correctly and the reported range is sensible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100