2929import java .util .List ;
3030import java .util .Optional ;
3131import java .util .Set ;
32+ import java .util .concurrent .Callable ;
3233import org .sosy_lab .common .ShutdownNotifier ;
3334import org .sosy_lab .common .UniqueIdGenerator ;
3435import org .sosy_lab .common .collect .PathCopyingPersistentTreeMap ;
@@ -53,7 +54,7 @@ abstract class PrincessAbstractProver<E> extends AbstractProverWithAllSat<E> {
5354 * Values returned by {@link Model#evaluate(Formula)}.
5455 *
5556 * <p>We need to record these to make sure that the values returned by the evaluator are
56- * consistant . Calling {@link #isUnsat()} will reset this list as the underlying model has been
57+ * consistent . Calling {@link #isUnsat()} will reset this list as the underlying model has been
5758 * updated.
5859 */
5960 protected final Set <IFormula > evaluatedTerms = new LinkedHashSet <>();
@@ -92,7 +93,10 @@ public boolean isUnsat() throws SolverException {
9293 final Value result = api .checkSat (true );
9394 if (result .equals (SimpleAPI .ProverStatus$ .MODULE$ .Sat ())) {
9495 wasLastSatCheckSat = true ;
95- evaluatedTerms .add (api .partialModelAsFormula ());
96+ if (this .generateModels || this .generateAllSat ) {
97+ // we only build the model if we have set the correct options
98+ evaluatedTerms .add (callOrThrow (api ::partialModelAsFormula ));
99+ }
96100 return false ;
97101 } else if (result .equals (SimpleAPI .ProverStatus$ .MODULE$ .Unsat ())) {
98102 return true ;
@@ -148,6 +152,9 @@ protected void popImpl() {
148152 * extend the original model.
149153 */
150154 Collection <IFormula > getEvaluatedTerms () {
155+ Preconditions .checkState (
156+ this .generateModels || this .generateAllSat ,
157+ "Model generation was not enabled, no evaluated terms available." );
151158 return Collections .unmodifiableCollection (evaluatedTerms );
152159 }
153160
@@ -168,22 +175,22 @@ public Model getModel() throws SolverException {
168175 @ SuppressWarnings ("resource" )
169176 @ Override
170177 protected PrincessModel getEvaluatorWithoutChecks () throws SolverException {
171- final PartialModel partialModel ;
172- try {
173- partialModel = partialModel ();
174- } catch (SimpleAPIException ex ) {
175- throw new SolverException (ex .getMessage (), ex );
176- }
178+ final PartialModel partialModel = callOrThrow (api ::partialModel );
177179 return registerEvaluator (new PrincessModel (this , partialModel , creator , api ));
178180 }
179181
180182 /**
181- * This method only exists to allow catching the exception from Scala in Java.
183+ * This method only exists to allow catching some exceptions from Scala in Java.
182184 *
183- * @throws SimpleAPIException if model can not be constructed.
185+ * @throws SolverException if the callable throws an Exception (including {@link
186+ * SimpleAPIException})
184187 */
185- private PartialModel partialModel () throws SimpleAPIException {
186- return api .partialModel ();
188+ private <T > T callOrThrow (Callable <T > callable ) throws SolverException {
189+ try {
190+ return callable .call ();
191+ } catch (Exception pException ) { // mainly for catching SimpleAPIException
192+ throw new SolverException (pException .getMessage (), pException );
193+ }
187194 }
188195
189196 @ Override
0 commit comments