We're updating the issue view to help you get more done. 

The Trace Replay sometimes seems to check output parameters on the wrong state

Description

For a machine of mine I am unable to replay certain JSON traces that I saved (not having changed the machine; just reloaded it).
It seems to me that the output parameters are sometimes checked in the successor state of a transition.

I do not fully understand the code; it would also be good to add a few more comments.

private Transition replayPersistentTransition(StateSpace stateSpace, Trace t,
PersistentTransition persistentTransition, boolean setCurrentAnimation) {
String predicate = new PredicateBuilder().addMap(persistentTransition.getParameters())
.toString();
final IEvalElement pred = stateSpace.getModel().parseFormula(predicate);
final GetOperationByPredicateCommand command = new GetOperationByPredicateCommand(stateSpace,
t.getCurrentState().getId(), persistentTransition.getOperationName(), pred, 1);
stateSpace.execute(command);
if (command.hasErrors()) {
String errorMessage = "Executing operation " + persistentTransition.getOperationName() + " with predicate "
+ predicate + " produced errors: " + Joiner.on(", ").join(command.getErrors());
Platform.runLater(() -> getReplayErrorAlert(errorMessage).showAndWait());
return null;
}
List<Transition> possibleTransitions = command.getNewTransitions();
if (possibleTransitions.isEmpty()) {
String errorMessage = "Executing operation " + persistentTransition.getOperationName() + " with predicate "
+ predicate + " produced errors: Operation not possible.";
Platform.runLater(() -> getReplayErrorAlert(errorMessage).showAndWait());
return null;
}
Transition trans = possibleTransitions.get(0);
if (!checkOutputParams(stateSpace, trans, persistentTransition, setCurrentAnimation)) {
return null;
}
return trans;
}

private boolean checkOutputParams(StateSpace stateSpace, Transition trans,
PersistentTransition persistentTransition, boolean setCurrentAnimation) {
String operationName = trans.getName();
OperationInfo machineOperationInfo = stateSpace.getLoadedMachine().getMachineOperationInfo(operationName);
if (machineOperationInfo != null) {
List<String> outputParameterNames = machineOperationInfo.getOutputParameterNames();
try {
List<BObject> translatedReturnValues = trans.getTranslatedReturnValues();
for (int i = 0; i < outputParameterNames.size(); i++) {
String outputParamName = outputParameterNames.get;
BObject paramValueFromTransition = translatedReturnValues.get;
if (persistentTransition.getOuputParameters().containsKey(outputParamName)) {
String stringValue = persistentTransition.getOuputParameters().get(outputParamName);
BObject bValue = Translator.translate(stringValue);
if (!bValue.equals(paramValueFromTransition)) {
// do we need further checks here?
// because the value translator does not
// support enum values properly
if (setCurrentAnimation) {
String errorMessage = String.format(
"Can not replay operation '%s'. The value of the ouput parameter '%s' does not match.\n"
+ "Value from trace file: %s\nComputed value: %s",
operationName, outputParamName, bValue.toString(), paramValueFromTransition);
Platform.runLater(() ->
Platform.runLater(() -> getReplayErrorAlert(errorMessage).showAndWait())
);
}
return false;
}
}

}
} catch (BCompoundException e) {
Platform.runLater(() -> stageManager.makeExceptionAlert("", e.getFirstException()).showAndWait());
return false;
}
}
return true;
}

Environment

None

Status

Assignee

Unassigned

Reporter

Michael Leuschel

Labels

None

Priority

Major