github / github/codeql

Java: FP in java/index-out-of-bounds when index known to be less than the length of the array

Open
#1,061 0 comments 0 reactions 0 assignees View on GitHub
false-positive Java
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

See: https://discuss.lgtm.com/t/java-false-positives/1787/2

```java
int x = ++i;
int y = ++i;
if (y < sb.length) {
byte[] hex = {sb[x], sb[y]};
^^^^^ -- flagged as alert
```

We know that (modulo overflow):

* `x` = `y - 1` --> `x` < `y`
* `y` < `sb.length`

Example: https://lgtm.com/projects/g/apache/accumulo/snapshot/b672a845ed56e9fd521ab85462cb6c45baa9abad/files/core/src/main/java/org/apache/accumulo/core/iterators/conf/ColumnSet.java?sort=name&dir=ASC&mode=heatmap#xb5a588dd1daff67e:1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.