ss: Replace some asserts by IllegalStateExceptions
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 15 Sep 2015 18:54:02 +0000 (14:54 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Sat, 31 Oct 2015 03:55:41 +0000 (23:55 -0400)
Change-Id: I692279143582c78b629d973107ec65e40f850793
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/56014
Reviewed-by: Hudson CI
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/HTNode.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/HistoryTree.java
statesystem/org.eclipse.tracecompass.statesystem.core/src/org/eclipse/tracecompass/internal/statesystem/core/backend/historytree/HistoryTreeBackend.java

index 95a1f002dfb2c740bb8c7c68780a7280378fc007..08727c1afe97cba90570aed3711a7c591c067719 100644 (file)
@@ -28,6 +28,8 @@ import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
 
+import com.google.common.collect.Iterables;
+
 /**
  * The base class for all the types of nodes that go in the History Tree.
  *
@@ -285,7 +287,9 @@ public abstract class HTNode {
              * If the offsets were right, the size of the Strings section should
              * be == to the expected size
              */
-            assert (curStringsEntryEndPos == fStringSectionOffset);
+            if (curStringsEntryEndPos != fStringSectionOffset) {
+                throw new IllegalStateException("Wrong size of Strings section: Actual: " + curStringsEntryEndPos + ", Expected: " + fStringSectionOffset); //$NON-NLS-1$ //$NON-NLS-2$
+            }
 
             /* Finally, write everything in the Buffer to disk */
 
@@ -294,7 +298,9 @@ public abstract class HTNode {
 
             buffer.flip();
             int res = fc.write(buffer);
-            assert (res == blockSize);
+            if (res != blockSize) {
+                throw new IllegalStateException("Wrong size of block written: Actual: " + res + ", Expected: " + blockSize); //$NON-NLS-1$ //$NON-NLS-2$
+            }
 
         } finally {
             fRwl.readLock().unlock();
@@ -412,7 +418,13 @@ public abstract class HTNode {
     public void closeThisNode(long endtime) {
         fRwl.writeLock().lock();
         try {
-            assert (endtime >= fNodeStart);
+            /**
+             * FIXME: was assert (endtime >= fNodeStart); but that exception
+             * is reached with an empty node that has start time endtime + 1
+             */
+//            if (endtime < fNodeStart) {
+//                throw new IllegalArgumentException("Endtime " + endtime + " cannot be lower than start time " + fNodeStart);
+//            }
 
             if (!fIntervals.isEmpty()) {
                 /*
@@ -420,7 +432,9 @@ public abstract class HTNode {
                  * EndTime > the one requested. Only need to check the last one
                  * since they are sorted
                  */
-                assert (endtime >= fIntervals.get(fIntervals.size() - 1).getEndTime());
+                if (endtime < Iterables.getLast(fIntervals).getEndTime()) {
+                    throw new IllegalArgumentException("Closing end time should be greater than or equal to the end time of the intervals of this node"); //$NON-NLS-1$
+                }
             }
 
             fNodeEnd = endtime;
index ebf47650658821efb14e865b0db9354b36721db3..32fbeb6e182026087b17d4a9dd2cf9802e055170 100644 (file)
@@ -474,7 +474,6 @@ public class HistoryTree {
              * No, this interval starts before the startTime of this node. We
              * need to check recursively in parents if it can fit.
              */
-            assert (indexOfNode >= 1);
             tryInsertAtNode(interval, indexOfNode - 1);
             return;
         }
@@ -663,7 +662,9 @@ public class HistoryTree {
          * Once we exit this loop, we should have found a children to follow. If
          * we didn't, there's a problem.
          */
-        assert (potentialNextSeqNb != currentNode.getSequenceNumber());
+        if (potentialNextSeqNb == currentNode.getSequenceNumber()) {
+            throw new IllegalStateException("No next child node found"); //$NON-NLS-1$
+        }
 
         /*
          * Since this code path is quite performance-critical, avoid iterating
index f26dea5b18c61961f9b7e87f9f73218400fd8a8b..24059780cf40e5c4592a7f7e7cc8f9b59b93c8e6 100644 (file)
@@ -322,7 +322,10 @@ public class HistoryTreeBackend implements IStateHistoryBackend {
         }
 
         ret = total / fSht.getNodeCount();
-        assert (ret >= 0 && ret <= 100);
+        /* The return value should be a percentage */
+        if (ret >= 0 && ret <= 100) {
+            throw new IllegalStateException("Average node usage is not a percentage: " + ret); //$NON-NLS-1$
+        }
         return (int) ret;
     }
 
This page took 0.027115 seconds and 5 git commands to generate.