typetools / typetools/checker-framework

Misuse of @LowerBoundBottom

Open
#2,637 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

False Positive (false warning or imprecision) Index
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.