9

I have a weird problem debugging an android application. To be accurate, I copy here the exact code I'm running on:

    // Get the puzzles from cache
List<PuzzleDetails> newPuzzles = m_cachedPuzzles.getPuzzles(count);

if(newPuzzles.size() > 0){
    // Remove from cache
    m_cachedPuzzles.removePuzzles(newPuzzles);  // LINE (A)     

    // Add the new puzzles from cache immediately
    m_ownedPuzzles.addPuzzles(newPuzzles);

    Log.d("requests", "" + newPuzzles.size() + " moved from cache to user");
}

int left = count - newPuzzles.size();       
String deviceId = ResourcesPublisher.getInstance().getDeviceId();

// Don't let anyone else use these points for now
ChallengePointsManagerImpl.getInstance().usePoints(left);       

Log.d("requests", "aquirePuzzles(" + left + ")");

// Get a list of requests for 'left' number of puzzles
RequestList reqList = getRequestList(left);

// TODO this is a bug, now
if(reqList.size() > 1){
    reqList = getRequestList(left);  // LINE (B)
}

When I run on this code, after stepping over the line (A) m_cachedPuzzles.removePuzzles(newPuzzles); The debugger "jumps" to the last line (B) reqList = getRequestList(left);

A simple check shows it really skipped all code between these code lines. For example the Log.d(...) was never called nor written.

Can anyone give me a clue why does it happen???

Thanks!

user1028741
  • 2,745
  • 6
  • 34
  • 68
  • 4
    If it's never being called then it's likely the source and executable are "out of sync". Try doing a clean, rebuild, and relaunch. – Dave Newton Jan 30 '12 at 00:37
  • I tried cleaning, but it still happens.. It's really strange - and happens everytime, so I feel even more obligated to examine and fix it. I just don't know where to begin... – user1028741 Jan 30 '12 at 00:53
  • Did you shut down the emulator and restart it? – Dave Newton Jan 30 '12 at 01:05
  • Yes, I just shut the emulator, and the Eclipse, and restarted them both. Didn't help me... – user1028741 Jan 30 '12 at 01:08
  • Did you verify the timestamp of the build artifact? – Dave Newton Jan 30 '12 at 01:16
  • If you mean the ".apk" file, I verified it now. It's updated. Also, when I add statements, I can debug them (as long as they are not between lines A-B). For example, I tried adding a try-catch statement to eliminate one of the answers. I can debug them - until I try to execute line (A) - then I jump to (B). – user1028741 Jan 30 '12 at 01:22
  • 1
    Huh. What if you copy just the source and create a new project? I'm still of the opinion it's a build/deploy issue, although I'm not sure what else to check. – Dave Newton Jan 30 '12 at 01:25
  • I tried that now, and surprisingly it works. As far as I can tell, the debugger no longer "jumps". I'm still VERY curious as to what the reason is. For now, I will try to continue with that new project I created, so I can debug... :) Thank you Dave! – user1028741 Jan 30 '12 at 21:21
  • Ah, the mysteries of debugging--I'm still pretty sure it's a build/deploy issue, probably something regarding getting the app "on" to the emulator, but... who knows. If you can re-create the issue w/ the old project, I'd try a few things like deleting the app on the emulator through the emulator's "remove app" management stuff, etc. – Dave Newton Jan 30 '12 at 23:38
  • I answered to similar question on: http://stackoverflow.com/questions/2968904/why-does-eclipse-skip-lines-when-i-debug-jboss – temuchin Nov 27 '12 at 14:30
  • Also got this, deleted app, restarted eclipse, clean, build, nothing helped. – User Jun 17 '13 at 11:23
  • Faced the same issue. – Maximin Oct 04 '13 at 12:00
  • With me, it was a bug, restarting Eclipse fixed it -_- – Breno Salgado Nov 10 '15 at 12:36

6 Answers6

3

Try to do a right click > refresh on the project as it appears on the Project Explorer after you compile the code and before you start debugging.

dimitrisli
  • 20,895
  • 12
  • 59
  • 63
0
        mIsReaded = (mIsReaded)?false:true;
        //mIsReaded = !mIsReaded;
        saveReadFlag();
        refreshUI();
        Toast.makeText(getSherlockActivity(),... 

In my case commented codeline cause the similar problem (two lines are skipped). For to solve it I just changed this line by codeline posted above (I mean mIsReaded = (mIsReaded)?false:true;) So different cases haves different solutions. It is result of code optimization by compiler, so please refactor something in (inside) m_cachedPuzzles.removePuzzles(newPuzzles);

user1700099
  • 466
  • 5
  • 6
0

I had the same problem. The thing is, you are probably debugging the code that is in your IDE and not the on on the server. You have to deploy the code from the IDE (Eclypse, Netbeans etc.) on the server. It worked for me! Good luck!

Lazar Zoltan
  • 135
  • 3
  • 14
0

Not directly related to Eclipse but I experienced a similar problem using the Xamarin Extension for Visual Studio and my realization may be of some help. I was developing an App with a Class library. when i made changes to the library then began emulating my App, the DLL wouldn't always rebuild so the debugger would step through the PDB as it was before my latest changes. After rebuilding the DLL, it would step through fine.

In short, rebuild dependencies if there are any changes made.

Hope you solve your issue. Have a good one

jgritten
  • 915
  • 1
  • 11
  • 20
0

comment TODO using multi-line comment

/*// TODO this is a bug, now*/

and try again.

0

Perhaps an exception was thrown from line A, and the next step corresponds to it closing off this stack frame?

poolie
  • 9,289
  • 1
  • 47
  • 74
  • I'm not sure I understand this explanation fully. Nevertheless, I tried to wrap line (A) in a try-catch statement, which catches all Throwables. I tried to debug again then, the debugger still "jumps" from line (A) to line (B)... – user1028741 Jan 30 '12 at 01:04
  • 1
    My idea (though it seems not to actually be true) is that sometimes a runtime exception will account for apparently surprising debug instruction pointer motion, and often the debugger will show the program being on the last line of a function as it exits from an exception. – poolie Jan 31 '12 at 22:31