Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta Para iniciantes
#395 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
82/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
java
Domínio
tooling

Direção de pesquisa

A falha está em visitCtFor em src/main/java/liquidjava/processor/refinement_checker/RefinementTypeChecker.java, onde uma lambda chama getElements em CtFor.getBody() por volta da linha 628; o mesmo caminho passa por visitLoop por volta da linha 658. Comece lendo como o corpo do laço é consumido ali e, em seguida, execute o reprodutor da issue, que tem um corpo vazio ;. Está pronto quando esse reprodutor imprime Correct! Passed Verification. e um teste de laço existente continua passando.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Java
Estrelas
69
Forks
36
Merge médio
2d 1h
PRs com merge (30d)
35

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de liquid-java/liquidjava

Todas as issues de liquid-java/liquidjava

Issues semelhantes

Mais issues de Java

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.