apache / apache/drill

Code contains multiple always true `byte <` checks

Open
#2,799 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
990
Avg merge
1d 8h
Merged PRs (30d)
5

Description

**Describe the bug**
The code contains multiple `x < ...` checks where `x` is a `byte` and the right-hand side is > 127 (= max `byte` value), so these conditions are always true:
- https://github.com/apache/drill/blob/5f8cdda2ac001d4267c3c903f3e92b9bf24e8713/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java#L92
- https://github.com/apache/drill/blob/5f8cdda2ac001d4267c3c903f3e92b9bf24e8713/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java#L116
- https://github.com/apache/drill/blob/5f8cdda2ac001d4267c3c903f3e92b9bf24e8713/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java#L127
- https://github.com/apache/drill/blob/5f8cdda2ac001d4267c3c903f3e92b9bf24e8713/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java#L1111
- https://github.com/apache/drill/blob/5f8cdda2ac001d4267c3c903f3e92b9bf24e8713/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/StringFunctions.java#L1260

Not completely sure what the fix here is, maybe `(byte & 0xFF) < ...`. And also for `StringFunctions` maybe it should be `128` (decimal) instead of `0x128` (hex, = 296 decimal); at least the `0x128` looks a bit suspicious.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the five reported checks in exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/CharSubstring.java at lines 92, 116, and 127, and StringFunctions.java at lines 1111 and 1260. Determine the intended byte bounds, including whether StringFunctions should use 128 or 0x128, then verify that all five conditions no longer contain always-true checks and preserve the intended string behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, data-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.