use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method initializeWalker.
@Before
public void initializeWalker() {
BehaviorCache behaviorCache = new BehaviorCache(squidClassLoader);
behaviorCache.setFileContext(null, semanticModel);
walker = new BytecodeEGWalker(behaviorCache, semanticModel);
}
use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method athrow_should_not_be_linked_to_next_label.
@Test
public void athrow_should_not_be_linked_to_next_label() throws Exception {
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse("class A {int field;}");
SquidClassLoader classLoader = new SquidClassLoader(Collections.singletonList(new File("src/test/JsrRet")));
SemanticModel semanticModel = SemanticModel.createFor(tree, classLoader);
BehaviorCache behaviorCache = new BehaviorCache(classLoader);
behaviorCache.setFileContext(null, semanticModel);
BytecodeEGWalker walker = new BytecodeEGWalker(behaviorCache, semanticModel);
MethodBehavior methodBehavior = walker.getMethodBehavior("org.apache.commons.io.FileUtils#readFileToString(Ljava/io/File;)Ljava/lang/String;", classLoader);
assertThat(methodBehavior.happyPathYields().collect(Collectors.toList())).hasSize(1);
assertThat(methodBehavior.exceptionalPathYields().collect(Collectors.toList())).hasSize(2);
}
use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.
the class BytecodeSECheckTest method getEGWalker.
private static BytecodeEGWalker getEGWalker() {
BehaviorCache behaviorCache = new BehaviorCache(squidClassLoader);
behaviorCache.setFileContext(null, semanticModel);
return new BytecodeEGWalker(behaviorCache, semanticModel);
}
use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method max_step_exception_should_log_warning_and_generate_behavior.
@Test
public void max_step_exception_should_log_warning_and_generate_behavior() {
BytecodeEGWalker bytecodeEGWalker = new BytecodeEGWalker(new BehaviorCache(squidClassLoader), semanticModel) {
@Override
int maxSteps() {
return 2;
}
};
MethodBehavior methodBehavior = getMethodBehavior(BytecodeTestClass.class, "fun(ZLjava/lang/Object;)Ljava/lang/Object;", bytecodeEGWalker);
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Dataflow analysis is incomplete for method org.sonar.java.bytecode.se.testdata.BytecodeTestClass#fun(ZLjava/lang/Object;)Ljava/lang/Object;" + " : Too many steps resolving org.sonar.java.bytecode.se.testdata.BytecodeTestClass#fun(ZLjava/lang/Object;)Ljava/lang/Object;");
assertThat(methodBehavior.isComplete()).isFalse();
assertThat(methodBehavior.isVisited()).isTrue();
}
use of org.sonar.java.se.xproc.BehaviorCache in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method getBytecodeEGWalker.
private static BytecodeEGWalker getBytecodeEGWalker(SquidClassLoader squidClassLoader) {
BehaviorCache behaviorCache = new BehaviorCache(squidClassLoader);
behaviorCache.setFileContext(null, semanticModel);
return new BytecodeEGWalker(behaviorCache, semanticModel);
}
Aggregations