tmf: Make the statesystem push/pop logic a bit more robust
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / statesystem / StateSystem.java
index 90e6f5b17c016c18a0955ac7bc932b4a038f792f..48764b96d32eb782e0a4787de4e3ddcc8c2d5397 100644 (file)
@@ -338,7 +338,6 @@ public class StateSystem {
     public void pushAttribute(long t, ITmfStateValue value, int attributeQuark)
             throws TimeRangeException, AttributeNotFoundException,
             StateValueTypeException {
-        assert (attributeQuark >= 0);
         Integer stackDepth = 0;
         int subAttributeQuark;
         ITmfStateValue previousSV = transState.getOngoingStateValue(attributeQuark);
@@ -351,16 +350,18 @@ public class StateSystem {
         } else if (previousSV.getType() == 0) {
             /* Previous value was an integer, all is good, use it */
             stackDepth = previousSV.unboxInt();
-            if (stackDepth >= 10) {
-                /*
-                 * Limit stackDepth to 10, to avoid having Attribute Trees grow
-                 * out of control due to buggy insertions
-                 */
-                assert (false);
-            }
         } else {
             /* Previous state of this attribute was another type? Not good! */
-            assert (false);
+            throw new StateValueTypeException();
+        }
+
+        if (stackDepth >= 10) {
+            /*
+             * Limit stackDepth to 10, to avoid having Attribute Trees grow out
+             * of control due to buggy insertions
+             */
+            String message = "Stack limit reached, not pushing"; //$NON-NLS-1$
+            throw new AttributeNotFoundException(message);
         }
 
         stackDepth++;
@@ -369,7 +370,7 @@ public class StateSystem {
 
         modifyAttribute(t, TmfStateValue.newValueInt(stackDepth),
                 attributeQuark);
-        transState.processStateChange(t, value, subAttributeQuark);
+        modifyAttribute(t, value, subAttributeQuark);
     }
 
     /**
@@ -393,22 +394,24 @@ public class StateSystem {
     public void popAttribute(long t, int attributeQuark)
             throws AttributeNotFoundException, TimeRangeException,
             StateValueTypeException {
-        assert (attributeQuark >= 0);
         Integer stackDepth;
         int subAttributeQuark;
         ITmfStateValue previousSV = transState.getOngoingStateValue(attributeQuark);
 
         if (previousSV.isNull()) {
+            /* Same as if stackDepth == 0, see below */
+            return;
+        }
+        if (previousSV.getType() != 0) {
             /*
-             * If the StateValue was null, this means this is the first time we
-             * use this attribute.
+             * The existing value was a string, this doesn't look like a valid
+             * stack attribute.
              */
-            stackDepth = 0;
-        } else {
-            assert (previousSV.getType() == 0);
-            stackDepth = previousSV.unboxInt();
+            throw new StateValueTypeException();
         }
 
+        stackDepth = previousSV.unboxInt();
+
         if (stackDepth == 0) {
             /*
              * Trying to pop an empty stack. This often happens at the start of
@@ -417,9 +420,13 @@ public class StateSystem {
              * silently.
              */
             return;
-        } else if (stackDepth < 0) {
+        }
+
+        if (stackDepth < 0) {
             /* This on the other hand should not happen... */
-            assert (false);
+            String message = "A top-level stack attribute " + //$NON-NLS-1$
+                    "cannot have a negative integer value."; //$NON-NLS-1$
+            throw new StateValueTypeException(message);
         }
 
         /* The attribute should already exist... */
This page took 0.024893 seconds and 5 git commands to generate.