use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class DebugMethodYieldsCheck method checkEndOfExecution.
@Override
public void checkEndOfExecution(CheckerContext context) {
MethodBehavior mb = ((CheckerDispatcher) context).methodBehavior();
IdentifierTree methodName = methodNames.pop();
if (mb != null) {
reportIssue(methodName, String.format("Method '%s' has %d method yields.", methodName.name(), mb.yields().size()), flowFromYield(mb, methodName));
}
}
use of org.sonar.java.se.xproc.MethodBehavior 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.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method exceptional_paths_should_be_enqueued.
@Test
public void exceptional_paths_should_be_enqueued() {
MethodBehavior mb = walker.getMethodBehavior(BytecodeEGWalkerExecuteTest.class.getCanonicalName() + "#enqueue_exceptional_paths(Lorg/sonar/java/bytecode/se/BytecodeEGWalkerExecuteTest;)Ljava/lang/Object;", squidClassLoader);
assertThat(mb.yields()).hasSize(2);
List<Constraint> resultConstraints = mb.yields().stream().map(y -> ((HappyPathYield) y).resultConstraint()).map(c -> c.get(ObjectConstraint.class)).collect(Collectors.toList());
assertThat(resultConstraints).contains(ObjectConstraint.NOT_NULL, ObjectConstraint.NULL);
}
use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BytecodeSECheckTest method method_with_numerical_operations.
@Test
public void method_with_numerical_operations() throws Exception {
BytecodeEGWalker walker = getEGWalker();
MethodBehavior behavior = walker.getMethodBehavior("org.sonar.java.bytecode.se.BytecodeSECheckTest#foo(II)I", squidClassLoader);
assertThat(behavior).isNotNull();
assertThat(behavior.yields()).hasSize(3);
assertThat(behavior.happyPathYields().map(HappyPathYield::toString).collect(Collectors.toList())).containsExactly("{params: [[], []], result: null (0)}");
assertThat(behavior.exceptionalPathYields().map(ExceptionalYield::toString).collect(Collectors.toList())).containsExactly("{params: [[NON_ZERO], []], exceptional (java.lang.IndexOutOfBoundsException)}", "{params: [[], []], exceptional (java.lang.IndexOutOfBoundsException)}");
}
use of org.sonar.java.se.xproc.MethodBehavior in project sonar-java by SonarSource.
the class BehaviorCacheTest method compute_beahvior_only_once.
@Test
public void compute_beahvior_only_once() throws Exception {
SymbolicExecutionVisitor sev = createSymbolicExecutionVisitor("src/test/resources/se/ComputeBehaviorOnce.java");
assertThat(sev.behaviorCache.behaviors.entrySet()).hasSize(5);
assertThat(logTester.logs(LoggerLevel.DEBUG)).containsOnlyOnce("Could not complete symbolic execution: ");
assertThat(sev.behaviorCache.behaviors.values()).allMatch(MethodBehavior::isVisited);
}
Aggregations