Java – the eclipse debugger jumps to the wrong return statement
I encountered a very strange situation I use Java (via eclipse Galileo) on the Android 2.1 platform to perform the following operations:
// 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 When getrotationmatrix (...) returns false, the eclipse debugger will display an IF statement (if (! Succeeded)) jump suddenly to return returnValue If no exception is thrown, logcat – even in verbose mode – will not receive an exception message It didn't even receive the message I entered in the code I tried the obvious method of cleaning up and restarting eclipse, but it didn't help I'm confused
The eclipse debugger told me that I was calling the second return statement However, adding other print statements to show will show that the first return statement is actually the arrived statement Maybe I stumbled upon an eclipse bug? Or can anyone explain this anomaly?
Solution
How are you sure it will jump to the last return? You have a return in if, which is likely to be called