DESCRIPTION

tmf: Bug 416660: -1 long state value is not long

- 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.

- Since nullValue can be unboxed into anything, it would be more
intuitive that adding nullValue to a number or appending nullValue to a
string would have no effect. Unboxing nullValue now returns 0, 0.0 or
"".

- Int and Long can now be unboxed into a double value.

Change-Id: I7c9e80963736e701a0b30f5f3009a0c7084527bb
Signed-off-by: Luciana Barry xxx@xxx.xxx


COMMENTS

author: Luciana Barry
date: 2013-09-13 20:16:44.000000000

Uploaded patch set 2.

-------------------------------------
author: Brenden Conley
date: 2013-09-13 20:16:49.000000000

Patch Set 2:

Build Started https://hudson.eclipse.org/linuxtools/job/linuxtools-gerrit/3471/

-------------------------------------
author: Luciana Barry
date: 2013-09-13 20:17:35.000000000

Patch Set 2:

> This is by design. Merely changing null.unboxInt() to return 0 instead of -1 will break MANY things only in the state system (like stack attributes, off the top of my head). And that's without talking about views.

There's a few things broken as it is now:

- You can't get a -1 Int value from the factory method but you can get one using incrementAttribute() on a -2 Int value

- Calling incrementAttribute() on this -1 Int value skips 0 and goes to 1.

- The State System Explorer view cannot display a factory-made -1 Int value (as it is nullValue), it shows a blank value.

If there is any code that is using the unboxed value of nullValue to check for null, that is badly designed code because it cannot differentiate with a real Int of that same value, it should use isNull(). I believe it's better to bite the bullet and correct that code now. Hopefully all of it is fixed by the patch now.

Mathematically, I think it makes more sense to use zero as the null value's numerical value.

> This is also by design. If we start to allow unboxing from one type to another, people might stop caring about what the actual type is, and always unbox their things into longs for example, doing costly casts over and over.

It's a point to consider, but I prefer to give the benefit of the doubt and the flexibility to the designers. In the code I'm doing now, I have to do floating point mathematical operations on a list of state values that can be a mix of Int, Long, Double or nullValue. Using unboxDouble() gives much cleaner code than having a if-else or switch statement on the value Type to figure out the correct unboxing method.

The unit tests should be correct now. The LTTng kernel state system creates a Threads/-1 attribute because the first events arrive before the Current_thread attribute has any value set. I considered updating the expected test state system with these events using the Threads/0 attribute (due to the current thread nullValue's int value), but decided against it because it would still be incorrect to consider that these events occurred in the swapper (0) thread. So the nullValue current thread continues uses the -1 attribute for the 'unknown' thread.

-------------------------------------
author: Brenden Conley
date: 2013-09-13 20:43:37.000000000

Patch Set 2: Verified+1

Build Successful 

https://hudson.eclipse.org/linuxtools/job/linuxtools-gerrit/3471/ : SUCCESS

-------------------------------------
author: Braxton Mccarthy
date: 2013-09-13 22:02:05.000000000

Patch Set 2:

I replied in bug 416660. Bugzilla is (slightly) more fit for discussing higher-level issues.

-------------------------------------
author: Braxton Mccarthy
date: 2013-11-14 19:08:37.000000000

Patch Set 2: Code-Review-1

We had another quick discussion on this ;)

What seems like the less intrusive solution that would bring an improvement would be to keep an int value corresponding to Type.NULL, but instead of -1 we could use Integer.MIN_VALUE, which is used less often in normal use cases.

-------------------------------------
author: Gerrit Code Review
date: 2013-11-28 21:23:58.000000000

The change could not be merged due to a path conflict.

Please rebase the change locally and upload the rebased commit for review.

-------------------------------------
