LoopConditionChecker reports a false positive when the increment operand is parenthesized
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- java
- Ambito
- testing-qa
Direzione di ricerca
Inizia leggendo il matcher LoopConditionChecker e i relativi test per le espressioni di aggiornamento dei cicli; il rapporto indica ASTHelpers.stripParentheses come possibile modo per gestire l’operando tra parentesi. Aggiungi un test di regressione che confronti i++ con (i)++ per un limite del ciclo costante, quindi conferma che nessuno dei due produce una segnalazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Error Prone version
Error Prone 2.49.0 (javac 21.0.8, --source/--target 21)
Affected checks
LoopConditionChecker
Description
Adding redundant parentheses around the operand of a loop's increment changes the result of LoopConditionChecker: i++ produces no finding, while (i)++ produces a false positive. In both cases, the loop's condition variable i is modified by the update. This manifests when the loop bound is a compile-time constant.
Per JLS §15.8.5, parentheses around an expression do not change its value, type, or constant-expression status. The two forms should therefore produce the same findings.
I verified the following pair on Error Prone 2.49.0:
| Check | Rewrite | BEFORE | AFTER | Effect |
|---|---|---|---|---|
LoopConditionChecker |
i++ → (i)++ |
0 | 1 | false positive |
The matcher appears to inspect the increment operand without looking through ParenthesizedTree. A possible fix is to unwrap the operand before matching it, for example with ASTHelpers.stripParentheses.
Reproducers
LoopConditionChecker — (i)++ produces a false positive
(i)++ denotes the same variable update as i++, so the loop's condition variable i is still modified in the update. The check reports it as never modified (this manifests when the loop bound is a compile-time constant).
// BEFORE — no finding
public class LoopParen {
void m() {
for (int i = 0; i < 10; i++) {
System.out.println(i);
}
}
}
// AFTER — false positive: "condition variable(s) never modified in loop body: i"
public class LoopParen {
void m() {
for (int i = 0; i < 10; (i)++) {
System.out.println(i);
}
}
}
Expected behavior
Neither version should produce a LoopConditionChecker finding. Both i++ and (i)++ modify the condition variable i, so adding redundant parentheses should not change the result.
Actual behavior
The BEFORE version produces 0 findings. The AFTER version produces 1 false positive: "condition variable(s) never modified in loop body: i", even though (i)++ modifies i.
- Lingua principale
- Java
- Stelle
- 7.3k
- Fork
- 827
- Merge medio
- 21h 35m
- PR unite (30g)
- 60
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/error-prone
-
ASTHelpers.getSymbol returns null for a parenthesized expression, while javac's TreeInfo.symbol returns the symbol insideForse già presa @vlsi l’ha presa 8 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google/error-prone#6223 ·
I maintainer di solito rispondono entro 1 giorno
-
InlineTrivialConstant misses an empty-string constant with a parenthesized initializerForse già presa @Youssef-Khogaly l’ha presa 8 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google/error-prone#6217 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
google/error-prone#6216 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
google/error-prone#6215 ·
I maintainer di solito rispondono entro 1 giorno
-
NonAtomicVolatileUpdate misses volatile increments and decrements with parenthesized operandsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google/error-prone#6214 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di google/error-prone
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
quarkiverse/quarkus-google-cloud-services#1188 ·
I maintainer di solito rispondono entro 1 giorno
-
Component: Frontend Component: Web Component Type: Maintenance
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
it-at-m/refarch-templates#1944 ·
I maintainer di solito rispondono entro 2 giorni
-
priority: p2 type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
googleapis/java-genai#1372 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 60/100