use of org.sonar.java.se.ProgramPoint in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_enqueuing_exceptional_yields2.
@Test
public void test_enqueuing_exceptional_yields2() {
BytecodeCFG cfg = SETestUtils.bytecodeCFG(TRY_WRONG_CATCH_SIGNATURE, squidClassLoader);
BytecodeCFG.Block b2 = cfg.blocks().get(2);
walker.programState = ProgramState.EMPTY_STATE.stackValue(new SymbolicValue()).stackValue(new SymbolicValue());
walker.programPosition = new ProgramPoint(b2).next().next();
walker.executeInstruction(b2.elements().get(3));
assertThat(walker.workList).hasSize(3);
assertThat(walker.workList.pop().programState.exitValue()).isNotNull().isInstanceOf(SymbolicValue.ExceptionalSymbolicValue.class).extracting(sv -> ((SymbolicValue.ExceptionalSymbolicValue) sv).exceptionType().fullyQualifiedName()).containsExactly("java.lang.IllegalStateException");
assertThat(walker.workList.pop().programState.exitValue()).isNull();
}
use of org.sonar.java.se.ProgramPoint in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method behavior_with_no_yield_should_stack_value.
@Test
public void behavior_with_no_yield_should_stack_value() throws Exception {
BehaviorCache behaviorCache = new BehaviorCache(squidClassLoader);
MethodBehavior methodBehavior = behaviorCache.get("org.mypackage.MyClass#MyMethod()Ljava/lang/Exception;");
methodBehavior.completed();
BytecodeEGWalker walker = new BytecodeEGWalker(behaviorCache, semanticModel);
walker.programState = ProgramState.EMPTY_STATE;
CFG.IBlock block = mock(CFG.IBlock.class);
when(block.successors()).thenReturn(Collections.emptySet());
walker.programPosition = new ProgramPoint(block);
walker.workList.clear();
walker.executeInstruction(new Instruction(INVOKESTATIC, new Instruction.FieldOrMethod("org.mypackage.MyClass", "MyMethod", "()Ljava/lang/Exception;")));
assertThat(walker.workList.getFirst().programState.peekValue()).isNotNull();
}
use of org.sonar.java.se.ProgramPoint in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_tableswitch.
@Test
public void test_tableswitch() throws Exception {
Instructions instr = new Instructions();
instr.visitVarInsn(ILOAD, 0);
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
Label l3 = new Label();
instr.visitTableSwitchInsn(0, 2, l3, new Label[] { l0, l1, l2 });
instr.visitLabel(l0);
instr.visitInsn(ICONST_0);
instr.visitVarInsn(ISTORE, 1);
instr.visitJumpInsn(GOTO, l3);
instr.visitLabel(l1);
instr.visitInsn(ICONST_0);
instr.visitVarInsn(ISTORE, 2);
instr.visitJumpInsn(GOTO, l3);
instr.visitLabel(l2);
instr.visitInsn(ICONST_0);
instr.visitVarInsn(ISTORE, 3);
instr.visitLabel(l3);
instr.visitInsn(RETURN);
BytecodeCFG cfg = instr.cfg();
CFG.IBlock<Instruction> entry = cfg.entry();
BytecodeEGWalker walker = new BytecodeEGWalker(null, null);
walker.programState = ProgramState.EMPTY_STATE.stackValue(new SymbolicValue());
walker.handleBlockExit(new ProgramPoint(entry));
assertThat(walker.workList).hasSize(entry.successors().size());
walker.workList.forEach(node -> {
assertThat(node.programState.peekValue()).isNull();
assertThat(entry.successors().contains(node.programPoint.block)).isTrue();
});
}
use of org.sonar.java.se.ProgramPoint in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_enqueuing_exceptional_yields.
@Test
public void test_enqueuing_exceptional_yields() {
BytecodeCFG cfg = SETestUtils.bytecodeCFG(TRY_CATCH_SIGNATURE, squidClassLoader);
BytecodeCFG.Block b2 = cfg.blocks().get(2);
walker.programState = ProgramState.EMPTY_STATE.stackValue(new SymbolicValue()).stackValue(new SymbolicValue());
walker.programPosition = new ProgramPoint(b2).next().next();
walker.executeInstruction(b2.elements().get(3));
assertThat(walker.workList).hasSize(4);
}
use of org.sonar.java.se.ProgramPoint in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method execute.
private ProgramState execute(Instruction instruction, ProgramState startingState) {
CFG.IBlock block = mock(CFG.IBlock.class);
when(block.successors()).thenReturn(Collections.emptySet());
walker.programPosition = new ProgramPoint(block);
walker.programState = startingState;
walker.workList.clear();
walker.executeInstruction(instruction);
ProgramState programState = walker.programState;
// X-PROC will enqueue new nodes
if (instruction.isInvoke() && !walker.workList.isEmpty()) {
programState = walker.workList.getFirst().programState;
}
return programState;
}
Aggregations