Weird behavior in Android's "if" block
<p>It walks like a bug, it chirps like a bug.... I need someone to confirm that it's a bug.</p>

<p>I was trying to get phone numbers from the address book with this code:</p>

<pre><code>public JSONObject getAllPhones() throws JSONException{ 
String mPhoneNumberProjection[] = new String[] {
        Contacts.Phones.NAME, Contacts.Phones.NUMBER, Contacts.Phones.TYPE
};
Uri phoneNumbersUri = Contacts.Phones.CONTENT_URI;
JSONObject result = new JSONObject(); 
JSONArray phones = new JSONArray();

Cursor myCursor = mApp.managedQuery(phoneNumbersUri, mPhoneNumberProjection, null, null, null);
mApp.startManagingCursor(myCursor);
if (!myCursor.isAfterLast()){
    myCursor.moveToFirst();
    do{
        JSONObject aRow = new JSONObject();
        for (int i = 0; i &lt; myCursor.getColumnCount(); i++){
            Log.d(LOG_TAG, myCursor.getColumnName(i) + " -&gt; " + myCursor.getString(i));
            aRow.put(myCursor.getColumnName(i), myCursor.getString(i));
        }
        phones.put(aRow);
    } while (myCursor.moveToNext());
}
result.put("phones", phones);
result.put("phoneTypes", getPhoneTypes());
return result;
}
</code></pre>

<p>But when there are no contacts, and !myCursor.isAfterLast() evaluates as "false", program steps into "for" loop. So it enters "if" block, skips several methods and lands in "for" loop... </p>

<p>When I extract this loop into a separate function, everything works ok.</p>

<p>I'm doing this in Eclipse Helios on 32-bit Vista. I tried cleaning the project, erasing Java cache, restarting computer, creating new AVD... I used Android 1.6 and Android 2.2, but the error stays on...</p>

<p>Can someone explain what's going on?</p>
