tmf: Bug 416660: -1 long state value is not long
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 12 Sep 2013 22:00:50 +0000 (18:00 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 29 Nov 2013 15:13:35 +0000 (10:13 -0500)
- Do not return nullValue when creating a new int or long with a value
of -1. This ensures that these values can be used and be differentiated
from a null value.

- Change occurences of -1 null value check to use isNull() method.

Change-Id: I7c9e80963736e701a0b30f5f3009a0c7084527bb
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/16396
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/internal/lttng2/kernel/core/stateprovider/LttngKernelStateProvider.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/backends/historytree/HTInterval.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/IntegerStateValue.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statevalue/TmfStateValue.java

index 38bf88ff7b7fcee0de298956233d0a639337d810..7de28ced3eea042912541751761a15c4cc201eb7 100644 (file)
@@ -109,7 +109,7 @@ public class LttngKernelStateProvider extends AbstractTmfStateProvider {
              */
             quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.CURRENT_THREAD);
             value = ss.queryOngoingState(quark);
-            int thread = value.unboxInt();
+            int thread = value.isNull() ? -1 : value.unboxInt();
             final Integer currentThreadNode = ss.getQuarkRelativeAndAdd(getNodeThreads(), String.valueOf(thread));
 
             /*
index e1b4a82794e94071127d75df6f30a89713925c35..eb368500ca0d3efacb8d7ba97f0d59389e939e11 100644 (file)
@@ -32,8 +32,8 @@ import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
 import org.eclipse.linuxtools.tmf.core.interval.TmfStateInterval;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystemBuilder;
 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
-import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
 import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue.Type;
+import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue;
 
 /**
  * This is the core class of the Generic State System. It contains all the
@@ -332,10 +332,11 @@ public class StateSystem implements ITmfStateSystemBuilder {
     public void incrementAttribute(long t, int attributeQuark)
             throws StateValueTypeException, TimeRangeException,
             AttributeNotFoundException {
-        int prevValue = queryOngoingState(attributeQuark).unboxInt();
-        if (prevValue == -1) {
-            /* if the attribute was previously null, start counting at 0 */
-            prevValue = 0;
+        ITmfStateValue stateValue = queryOngoingState(attributeQuark);
+        int prevValue = 0;
+        /* if the attribute was previously null, start counting at 0 */
+        if (!stateValue.isNull()) {
+            prevValue = stateValue.unboxInt();
         }
         modifyAttribute(t, TmfStateValue.newValueInt(prevValue + 1),
                 attributeQuark);
@@ -407,9 +408,8 @@ public class StateSystem implements ITmfStateSystemBuilder {
 
         if (stackDepth <= 0) {
             /* This on the other hand should not happen... */
-            /* the case where == -1 was handled previously by .isNull() */
             String message = "A top-level stack attribute cannot " + //$NON-NLS-1$
-                    "have a value of 0 or less (except -1/null)."; //$NON-NLS-1$
+                    "have a value of 0 or less."; //$NON-NLS-1$
             throw new StateValueTypeException(message);
         }
 
@@ -420,7 +420,7 @@ public class StateSystem implements ITmfStateSystemBuilder {
         /* Update the state value of the stack-attribute */
         ITmfStateValue nextSV;
         if (--stackDepth == 0 ) {
-            /* Jump over "0" and store -1 (a null state value) */
+            /* Store a null state value */
             nextSV = TmfStateValue.nullValue();
         } else {
             nextSV = TmfStateValue.newValueInt(stackDepth);
@@ -567,12 +567,14 @@ public class StateSystem implements ITmfStateSystemBuilder {
     public ITmfStateInterval querySingleStackTop(long t, int stackAttributeQuark)
             throws StateValueTypeException, AttributeNotFoundException,
             TimeRangeException, StateSystemDisposedException {
-        Integer curStackDepth = querySingleState(t, stackAttributeQuark).getStateValue().unboxInt();
+        ITmfStateValue curStackStateValue = querySingleState(t, stackAttributeQuark).getStateValue();
 
-        if (curStackDepth == -1) {
+        if (curStackStateValue.isNull()) {
             /* There is nothing stored in this stack at this moment */
             return null;
-        } else if (curStackDepth < -1 || curStackDepth == 0) {
+        }
+        Integer curStackDepth = curStackStateValue.unboxInt();
+        if (curStackDepth <= 0) {
             /*
              * This attribute is an integer attribute, but it doesn't seem like
              * it's used as a stack-attribute...
index 70a27d0d0573a109104dc7af24e1edadbe47252e..9b4bdb36f0db9517e2e9e373190fe9da113d334c 100644 (file)
@@ -237,8 +237,7 @@ final class HTInterval implements ITmfStateInterval, Comparable<HTInterval> {
 
         case TYPE_NULL:
         case TYPE_INTEGER:
-            /* We write the 'valueOffset' field as a straight value. In the case
-             * of a null value, it will be unboxed as -1 */
+            /* We write the 'valueOffset' field as a straight value. */
             try {
                 buffer.putInt(sv.unboxInt());
             } catch (StateValueTypeException e) {
index 9ac7d5ec8fc5a0b208510d1e6c5fd63055140ed7..fdc288d97cc3e2345fa572432967a38ee5828e02 100644 (file)
@@ -68,7 +68,7 @@ final class IntegerStateValue extends TmfStateValue {
 
     @Override
     public long unboxLong() {
-        /* It's always safe to up-cast a int into a long */
+        /* It's always safe to up-cast an int into a long */
         return value;
     }
 }
index a2eaca6d6248fb5015ca786df06b69b7be6250b2..6330cae2b1c5016e381d7c122d19efd8ab54148d 100644 (file)
@@ -56,9 +56,6 @@ public abstract class TmfStateValue implements ITmfStateValue {
      * @return The newly-created TmfStateValue object
      */
     public static TmfStateValue newValueInt(int intValue) {
-        if (intValue == -1) {
-            return nullValue();
-        }
         return new IntegerStateValue(intValue);
     }
 
@@ -71,9 +68,6 @@ public abstract class TmfStateValue implements ITmfStateValue {
      * @since 2.0
      */
     public static TmfStateValue newValueLong(long longValue) {
-        if (longValue == -1) {
-            return nullValue();
-        }
         return new LongStateValue(longValue);
     }
 
@@ -85,9 +79,6 @@ public abstract class TmfStateValue implements ITmfStateValue {
      * @return The newly-created TmfStateValue object
      */
     public static TmfStateValue newValueDouble(double value) {
-        if (Double.isNaN(value)) {
-            return nullValue();
-        }
         return new DoubleStateValue(value);
     }
 
This page took 0.029818 seconds and 5 git commands to generate.