typetools / typetools/checker-framework

Index Checker `startsWith` refinement

Open
#5,201 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

False Positive (false warning or imprecision) good first issue
Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

Consider this code (which is in checker/tests/index/StartsEndsWith.java):

  final String prefix;

  String propertyName(String methodName) {
    if (methodName.startsWith(prefix)) {
      String result = methodName.substring(prefix.length());
      return result;
    } else {
      return null;
    }
  }

The Index Checker issues the following warning:

StartsEndsWith.java:17: error: [argument] incompatible argument for parameter beginIndex of substring.
      String result = methodName.substring(prefix.length());
                                                        ^
  found   : @LTEqLengthOf("this.prefix") int
  required: @LTEqLengthOf("methodName") int

but the code is correct because methodName is at least as long as this.prefix.

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

Reproduce the warning using checker/tests/index/StartsEndsWith.java and read the Index Checker handling involved in startsWith refinement. Determine how the length relationship between methodName and prefix should be represented, then verify that the shown substring call is accepted without weakening valid index checks.

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
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.