ExceptionalYield extends MethodYield { public Type exceptionType(Sema semanticModel) { if (exceptionType == null) { return Symbols.unknownType; } Type type = semanticModel.getClassType(this.exceptionType); return type == null ? Symbols.unknownType : type; } ExceptionalYield(MethodBehavior behavior);  ExceptionalYield(ExplodedGraph.Node node, MethodBehavior behavior); @Override Stream<ProgramState> statesAfterInvocation(List<SymbolicValue> invocationArguments, List<Type> invocationTypes, ProgramState programState,
    Supplier<SymbolicValue> svSupplier); void setExceptionType(@Nullable String exceptionType); @Nullable String getExceptionType(); Type exceptionType(Sema semanticModel); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test void exceptional_yields() { Pair<SymbolicExecutionVisitor, Sema> sevAndSemantic = createSymbolicExecutionVisitorAndSemantic("src/test/files/se/ExceptionalYields.java"); SymbolicExecutionVisitor sev = sevAndSemantic.a; Sema semanticModel = sevAndSemantic.b; MethodBehavior mb = getMethodBehavior(sev, "myMethod"); assertThat(mb.yields()).hasSize(4); List<ExceptionalYield> exceptionalYields = mb.exceptionalPathYields().collect(Collectors.toList()); assertThat(exceptionalYields).hasSize(3); Optional<ExceptionalYield> runtimeException = exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).isUnknown()).findFirst(); assertThat(runtimeException).isPresent(); MethodYield runtimeExceptionYield = runtimeException.get(); assertThat(runtimeExceptionYield.parametersConstraints.get(0).get(BooleanConstraint.class)).isEqualTo(BooleanConstraint.FALSE); Optional<ExceptionalYield> implicitException = exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).is("org.foo.MyException2")).findFirst(); assertThat(implicitException).isPresent(); MethodYield implicitExceptionYield = implicitException.get(); assertThat(implicitExceptionYield.parametersConstraints.get(0).get(BooleanConstraint.class)).isEqualTo(BooleanConstraint.FALSE); Optional<ExceptionalYield> explicitException = exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).is("org.foo.MyException1")).findFirst(); assertThat(explicitException).isPresent(); MethodYield explicitExceptionYield = explicitException.get(); assertThat(explicitExceptionYield.parametersConstraints.get(0).get(BooleanConstraint.class)).isEqualTo(BooleanConstraint.TRUE); }
@Test void exceptional_yields_void_method() { Pair<SymbolicExecutionVisitor, Sema> sevAndSemantic = createSymbolicExecutionVisitorAndSemantic("src/test/files/se/ExceptionalYieldsVoidMethod.java"); SymbolicExecutionVisitor sev = sevAndSemantic.a; Sema semanticModel = sevAndSemantic.b; MethodBehavior mb = getMethodBehavior(sev, "myVoidMethod"); assertThat(mb.yields()).hasSize(4); List<ExceptionalYield> exceptionalYields = mb.exceptionalPathYields().collect(Collectors.toList()); assertThat(exceptionalYields).hasSize(3); assertThat(exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).isUnknown()).count()).isEqualTo(1); MethodYield explicitExceptionYield = exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).is("org.foo.MyException1")).findAny().get(); assertThat(explicitExceptionYield.parametersConstraints.get(0).get(ObjectConstraint.class)).isEqualTo(ObjectConstraint.NULL); MethodYield implicitExceptionYield = exceptionalYields.stream().filter(y -> y.exceptionType(semanticModel).is("org.foo.MyException2")).findAny().get(); assertThat(implicitExceptionYield.parametersConstraints.get(0).get(ObjectConstraint.class)).isEqualTo(ObjectConstraint.NOT_NULL); }