I have a class with the following method:
/**
* @param contact
* @return
*/
public long create(Contact contact) {
ContentValues contactValues = buildContentValues(contact);
try {
return getDb().insert(CONTACTS_TABLE_NAME, null, contactValues);
} catch (SQLiteConstraintException sce) {
sce.printStackTrace(); // line 1
log.debug("Error inserting:" + contact, sce); //line2
return getDb().update(CONTACTS_TABLE_NAME, contactValues, COLUMN_ID + "=" + contact.userInfo.id, null); //line 3
}
}
I am running this using an AndroidTestCase as an Android Junit Test from Eclipse Android SDK. When I first started running it, my test was failing. When I stepped through it, it was handling the exception and running the update (marked as line 3).
Hmm...wonder why that is. So I added logging information and re-ran the unit test. When I step through the code, it goes directly to line 3 in the debugger without printing the stack trace. Strange, I think, but this is probably just some code stuck in the bin directory. So I run a project clean and run it again. EXACT same results.
It's a trick, I think. I set a breakpoint on line 3 AND line 1 and re-run the test. Test skips directly to line 3 without hitting the line 1 breakpoint.
Hmmm....Maybe the codes stuck in the bin directory and eclipse can't delete it with a clean. I've seen this happen before. So, I stop eclipse, go to the bin directory, and manually delete all of the files there. I then restart eclipse refresh the file system, run a project clean and then re-run my test. No change.
WTF?
Aha! I think, the code is stuck on the phone. I uninstall all of our software, including the test apps from the phone. Project->Clean and re-run the test. Still no change.
WTFF?
So, I think, I've tested on this phone so much, some code fragments stuck somewhere in there. I use the Android tool and build a fresh emulator. Project->Clean, run the test on the emulator. Exact same results.
FWTFF?
So, I wonder around aimlessly for a bit and have no ideas what to try next, so I'm posting here.
After this was posted, I spoke with a colleague and showed him the problem I was having. He has an eclipse setup slightly different than mine. He used my source and re-created the issue exactly.
FFFFF.