Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,9 @@ public void visitCtWhile(CtWhile whileLoop) {
tryAddEdge(lastNode, branch);
tryAddEdge(branch, convergenceNode);
lastNode = branch;
whileLoop.getBody().accept(this);
if (whileLoop.getBody() != null) {
whileLoop.getBody().accept(this);
}
tryAddEdge(lastNode, branch, true, false);
lastNode = convergenceNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
package fr.inria.controlflow;

import org.junit.jupiter.api.Test;
import spoon.Launcher;
import spoon.reflect.code.CtStatement;
import spoon.reflect.declaration.CtElement;
import spoon.support.reflect.code.CtIfImpl;
import static fr.inria.controlflow.BranchKind.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

Expand Down Expand Up @@ -169,4 +172,12 @@ public void testCounting() {
assertEquals(3, graph.statementCount());
}

@Test
void issue4803() {
// contract: analyzing while(true); should not throw a NPE. See issue 4803
ControlFlowBuilder builder = new ControlFlowBuilder();
Launcher launcher = new Launcher();
CtElement element = launcher.getFactory().createCodeSnippetStatement("while(true)").compile();
assertDoesNotThrow(() -> builder.build(element));
}
}