Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse debugger is jumping to the wrong return statement

I've run into a really weird situation. I'm doing the following in Java (through Eclipse Galileo) on the Android 2.1 platform:

// Get gravity & geomagnetic data to return to the caller.
final int SIZE_GRAVITY = 3, SIZE_GEOMAGNETIC = 3;
final float[] NOT_USED = null;
float[] outGravity = new float[SIZE_GRAVITY];
float[] outGeomagnetic = new float[SIZE_GEOMAGNETIC];
final String NO_DATA_COULD_BE_READ = null;
boolean succeeded = SensorManager.getRotationMatrix(NOT_USED, NOT_USED, outGravity, outGeomagnetic);
if (!succeeded)
{
    return NO_DATA_COULD_BE_READ;
}

Log.v("Test", "This should be printed - but it isn't!!");

// Prepare the data to return.
final int X = 0, Y = 1, Z = 2;
final String FIELD_SEPARATOR = ",", VECTOR_SEPARATOR = ";";
String returnValue = "" +
    outGravity[X] + FIELD_SEPARATOR +
    outGravity[Y] + FIELD_SEPARATOR +
    outGravity[Z] + VECTOR_SEPARATOR + 
    outGeomagnetic[X] + FIELD_SEPARATOR +
    outGeomagnetic[Y] + FIELD_SEPARATOR +
    outGeomagnetic[Z];

// Return data.
return returnValue;

When SensorManager.getRotationMatrix(...) returns false, the Eclipse debugger shows that the if-statement that says if (!succeeded) suddenly jumps to return returnValue;. No exception is thrown and LogCat - even on verbose mode - receives no unusual message. It doesn't even receive the message I put in the code. I tried the obvious clean-and-restart-Eclipse approach and that didn't help. I'm very confused.

The Eclipse debugger is telling me that the second return statement is being called. However, putting additional print statements in shows that the first return statement is actually the one being reached. Perhaps I've stumbled across an Eclipse bug? Or anyone could explain this anomaly?

like image 938
Dylan Knowles Avatar asked Aug 24 '26 02:08

Dylan Knowles


2 Answers

Looks like succeeded is false. Debugging will make it look like the method jumps to the bottom return when you do any return. Put a log before

  return NO_DATA_COULD_BE_READ;
like image 111
jqpubliq Avatar answered Aug 25 '26 16:08

jqpubliq


How are you sure that it jumps to the last return? You have a return in the if, this is most likely this one which is called.

like image 31
Guillaume Brunerie Avatar answered Aug 25 '26 17:08

Guillaume Brunerie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!