From 1a85c5423928157236c2eb78735acb6be74b7edc Mon Sep 17 00:00:00 2001
From: apvrille <ludovic.apvrille@eurecom.fr>
Date: Wed, 22 Mar 2017 15:01:19 +0100
Subject: [PATCH] Resolving bug on crash of avatar model checker when the
 avatar spec has no termination elt

---
 src/avatartranslator/AvatarStateMachine.java | 34 +++++++++++++++++---
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/avatartranslator/AvatarStateMachine.java b/src/avatartranslator/AvatarStateMachine.java
index 9cfdbb88d1..77fc44eec8 100644
--- a/src/avatartranslator/AvatarStateMachine.java
+++ b/src/avatartranslator/AvatarStateMachine.java
@@ -194,13 +194,37 @@ public class AvatarStateMachine extends AvatarElement {
 
     // Add missing implicit states.
     public void makeFullStates(AvatarBlock _block) {
+	addStatesToEmptyNonTerminalEmptyNext(_block);
         addStatesToTransitionsBetweenTwoNonStates(_block);
         addStatesToActionTransitions(_block);
-        addStateToNonEmptyTransitionsBetweenNonStateToState(_block);
-    }
-
-
-    private void addStateToNonEmptyTransitionsBetweenNonStateToState(AvatarBlock _block) {
+        addStatesToNonEmptyTransitionsBetweenNonStateToState(_block);
+    }
+
+
+    private void addStatesToEmptyNonTerminalEmptyNext(AvatarBlock _b) {
+	ArrayList<AvatarStateMachineElement> toConsider = new ArrayList<AvatarStateMachineElement>();
+	for(AvatarStateMachineElement elt: elements) {
+            if (!(elt instanceof AvatarStopState)) {
+		if (elt.getNext(0) == null) {
+		    // Missing state
+		    toConsider.add(elt);
+		}
+	    }
+	}
+	
+	for(AvatarStateMachineElement elt: toConsider) {
+	    AvatarStopState stopMe = new AvatarStopState("stopCreated", elt.getReferenceObject());
+	    addElement(stopMe);
+	    AvatarTransition tr = new AvatarTransition(_b, "trForStopCreated", elt.getReferenceObject());
+	    addElement(tr);
+	    elt.addNext(tr);
+	    tr.addNext(stopMe);
+	}
+	
+    }
+    
+
+    private void addStatesToNonEmptyTransitionsBetweenNonStateToState(AvatarBlock _block) {
         AvatarStateMachineElement next;
         AvatarStateMachineElement previous;
         ArrayList<AvatarStateMachineElement> toAdd = new ArrayList<AvatarStateMachineElement>();
-- 
GitLab