typetools / typetools/checker-framework
Misuse of @LowerBoundBottom
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{
void issue(int[] a, int[] b){
int i;
for(i = 0 ; i < b.length && i < a.length ; i ++);
for( ; i < a.length ; i ++){
a[i] = 0;
}
}
}
Run it by: javac -processor index tryit.java
Output:
tryit.java:6: error: [array.access.unsafe.low] Potentially unsafe array access: the index could be negative.
a[i] = 0;
^
found : @LowerBoundBottom int
required: an integer >= 0 (@NonNegative or @Positive)
1 error
Which shouldn't be the case, clearly. However, when I annotate i as @NonNegative, the error is not issued.
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
Start by compiling the provided tryit.java reproducer with javac -processor index tryit.java, then compare it with the version where i is annotated @NonNegative. Investigate how the loop and @LowerBoundBottom result in the unsafe array-access diagnostic. Done means the unannotated code no longer reports a potentially negative index while the annotation case remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100