I am practicing for my UML exam next monday and on of the questions is what the outcome is of the following diagram, I thought the diagram is not valid because the value of x is exactly 9 the first time. The guards are: Greater then 9 and 10 or greater. So both guards are not true, because the effect after the guard (+1) is run after the guard is evaluated. Am I missing something or is this indeed not rigth:
I think the diagram is not valid because both guards are false.

Edited - the ultimate (but long) answer
The question at stake in this edge case
Normally, an
exitaction cleans the situation before leaving a state. It's therefore uncommon in real life to have a cleanup action that might affect a transition.Assuming that x is a property not accessed by any other concurrent state machine, we can follow the diagram and see that the machine enters the first states with x being successively 0, 2, 4, 6, until it enters with x=8 the state with two outgoing transitions.
The edge case is that the
exitaction could have an impact on the condition of the guard. The key question is then whether the guard is evaluated before or after the exit behavior:[x<9]would be true and the transition fire.Unauthoritative answer
Unfortunately the UML specs are not super-clear in this regard. I'd expected a clear statement about when the guard is evaluated, but the information is diluted over several paragraphs and subject to different interpretations (see comments exchanged with qwerty_so).
So I ended up looking at The UML user guide, a book that is not authoritative and no longer aligned with the latest UML specs, but which has the advantage of being written very clearly by the inventors of UML before OMG made it very abstract.
Their message is clear: the transition guard is evaluated when an trigerring event matching the transition is received. This means that it is evaluated before the
exitbehavior, in line with the logic exposed by qwerty_so.The question then remains when no triggering event is specified, although we can understand that it has to do with the state being ready to exit.
What do the specs say
Pager 315 of the UML 2.5.1 specs we read that:
But what are the enabled transitions? The UML specs require in the section about run-to-completion several conditions and in particular that:
The full path from source to target requires to leave the state. P 311/312 of the UML 2.5.1 specification, explain in this regard that:
So, this would mean that there is no path that is enabled, because exiting would mean x to be 9, and both guards would evaluate to false. This was the conclusion of my initial answer. But the contradiction with the user's guide left me no sleep.
Reading and reading again, I finally found two other relevant paragraphs. The first one explains the case of unguarded simple transitions when no triggering event is specified (P.314):
The key in this paragraphe above, is that the
exitis not mentioned in the completion of the state. This allowed me to make the link with The UML user's guide: The event triggering the transition is when theentryanddoare completed, independently ofexit.Another paragraph about the guard mentions compound transition. I initially thought that the "compound transition" referred to a special case with sub-state machines or composite states that would not be relevant in our case:
It appears however that the "compound transition" corresponds to the traversal of machine between two stable configurations. It is also explained that one of the case of a compound transition is the completion transition:
If we put the two together, this means that the guard is evaluated before the exit behavior. This is complex but unambiguous and overrides my former interoperation based on the "complete path".
Conclusion
Your machine would fire the transition with the guard x<9 and would then do another loop and then fire the one with >=10 and finally reach the end.
The specs are very tricky to read in that matter. It's true that they cover a broad number of cases, but there is already a note (showing that it was not sufficiently clear). This note deservers to be amended: