use of org.sonar.java.bytecode.loader.SquidClassLoader 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.bytecode.loader.SquidClassLoader 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.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method initializeClassLoaderAndSemanticModel.
@BeforeClass
public static void initializeClassLoaderAndSemanticModel() {
List<File> files = new ArrayList<>(FileUtils.listFiles(new File("target/test-jars"), new String[] { "jar", "zip" }, true));
files.add(new File("target/classes"));
files.add(new File("target/test-classes"));
squidClassLoader = new SquidClassLoader(files);
File file = new File("src/test/java/org/sonar/java/bytecode/se/BytecodeEGWalkerExecuteTest.java");
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse(file);
semanticModel = SemanticModel.createFor(tree, squidClassLoader);
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class BytecodeSECheckTest method initializeWalker.
@BeforeClass
public static void initializeWalker() {
List<File> files = new ArrayList<>();
files.add(new File("target/test-classes"));
squidClassLoader = new SquidClassLoader(files);
CompilationUnitTree tree = (CompilationUnitTree) JavaParser.createParser().parse("class A {}");
semanticModel = SemanticModel.createFor(tree, squidClassLoader);
walker = getEGWalker();
}
use of org.sonar.java.bytecode.loader.SquidClassLoader in project sonar-java by SonarSource.
the class CFGTest method buildCFGFromCUT.
private static CFG buildCFGFromCUT(CompilationUnitTree cut) {
SemanticModel.createFor(cut, new SquidClassLoader(Collections.emptyList()));
final MethodTree tree = ((MethodTree) ((ClassTree) cut.types().get(0)).members().get(0));
return CFG.build(tree);
}
Aggregations