checkstyle / checkstyle/checkstyle
False positive in LogicConditionNeedOptimization for valid && condition expression
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 4.2k
- Avg merge
- 22h 23m
- Merged PRs (30d)
- 232
Description
From comment : https://github.com/checkstyle/checkstyle/pull/17436#discussion_r2233295802
The LogicConditionNeedOptimization check flags a valid and safe Java condition using instanceof pattern matching as needing optimization. This is a false positive because the evaluation order is guaranteed and safe in modern Java.
Code to reproduce:
`return object instanceof IntMatchFilterElement other && matchValue == other.matchValue;`
This triggers:
[checkstyle] [ERROR] C:\projects\checkstyle\src\main\java\com\puppycrawl\tools\checkstyle\filters\IntMatchFilterElement.java:56:62: Condition with && at line 56 position 61 need optimization. All method calls are advised to move to end of logic expression. [LogicConditionNeedOptimization]
Contributor guide
Research direction
Start by reproducing the diagnostic from IntMatchFilterElement.java and tracing the LogicConditionNeedOptimization check that reports it. Add a regression test for the instanceof pattern-matching condition, then verify the check no longer flags this valid expression while existing optimization diagnostics still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100