Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Verifier crashes on a `for` loop whose body is an empty statement (`for (...) ;`)

Aperta Adatta ai principianti
#395 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

Il crash si trova in visitCtFor in src/main/java/liquidjava/processor/refinement_checker/RefinementTypeChecker.java, dove una lambda chiama getElements su CtFor.getBody() intorno alla riga 628; lo stesso percorso attraversa visitLoop intorno alla riga 658. Inizia leggendo come il corpo del ciclo viene elaborato lì, poi esegui il reproducer presente nell'issue, che ha un corpo vuoto ;. È completato quando quel reproducer stampa Correct! Passed Verification. e un test esistente sui cicli continua a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Impact: verification stops with an internal error on any for loop whose body is an empty statement (;).

Description

for (...; ...; ...) ; has no body block: CtFor.getBody() is null, and RefinementTypeChecker.visitCtFor calls getElements on it (RefinementTypeChecker.java:628). Nothing in the loop needs a refinement, so an empty body could be checked as an empty block.

Minimal reproducer

public class Repro {
    static int total(int[] counts) {
        int total = 0;
        for (int i = 0; i < counts.length; total += counts[i], i++)
            ;
        return total;
    }
}

Expected

Correct! Passed Verification.

Actual

Exception in thread "main" java.lang.RuntimeException: 
Error while checking CtMethodImpl
  on total(int[] counts) { 
  at Repro.java:2
  with 
Error while checking CtBlockImpl
  on { 
  at Repro.java:2
  with 
Error while checking CtForImpl
  on for (int i = 0; i < counts.length; total += counts[i], i++) 
  at Repro.java:4
  with Cannot invoke "spoon.reflect.code.CtStatement.getElements(spoon.reflect.visitor.Filter)" because the return value of "spoon.reflect.code.CtFor.getBody()" is null
...
Caused by: java.lang.NullPointerException: Cannot invoke "spoon.reflect.code.CtStatement.getElements(spoon.reflect.visitor.Filter)" because the return value of "spoon.reflect.code.CtFor.getBody()" is null
	at liquidjava.processor.refinement_checker.RefinementTypeChecker.lambda$visitCtFor$4(RefinementTypeChecker.java:628)
	at liquidjava.processor.refinement_checker.RefinementTypeChecker.visitLoop(RefinementTypeChecker.java:658)
	at liquidjava.processor.refinement_checker.RefinementTypeChecker.visitCtFor(RefinementTypeChecker.java:623)

Reproduced on main at ad055b49 (liquidjava-verifier 0.0.35).

Real-world file that hits it

  • for (int i = 0; i < updateCount.length; cnt += updateCount[i], i++) ; — tejeswarp/tungsten-replicator (file)

Context

Found while running LiquidJava on the original repository files of 53 real-world typestate and refinement bugs (the files our study exercises were simplified from). Each file is verified on its own, as a user would verify one file of a project, so the project's other classes and its dependencies are not on the classpath.

Lingua principale
Java
Stelle
67
Fork
36
Merge medio
2g 2h
PR unite (30g)
34

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di liquid-java/liquidjava

Tutte le issue di liquid-java/liquidjava

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.