dm78
dm78

Reputation: 1600

Eclipse debugging Android app - debugger shows wrong line executing

While implementing Twitter integration in my app, I discovered the following oddness of the Eclipse debugger. What is causing this?

I'm using this AsyncTask for getting a request token from twitter using twitter4j 3.0.3.

    public class TwitterRequestAsync extends AsyncTask<Void, Void, RequestToken> {

        private Context context;

        public TwitterRequestAsync(Context context) {

            this.context = context;
        }

        @Override
        protected RequestToken doInBackground( Void... params ) {

            Twitter twitter = getTwitter();     // getTwitter() is in enclosing class
            try {
                RequestToken token = twitter.getOAuthRequestToken();
                return token;
            }
            catch (TwitterException e) {
                Log.e( TAG, e.getMessage(), e );
                return null;
            }
        }

        @Override
        protected void onPostExecute( RequestToken result ) {

            super.onPostExecute( result );
            if ( result != null ) {
                // stuffs concerning request token here
            }
        }

    }

When I debug this code it appears that there is an exception thrown when getOAuthRequestToken() executes and the next line that the debugger shows executing is in the catch clause, return null;

However, the result that is returned to onPostExecute(...) is a valid request token, so the debugger is doing something weird. I've cleaned my project and restarted Eclipse each multiple times with no change in this behavior. Am I broken?

Upvotes: 0

Views: 411

Answers (2)

fadden
fadden

Reputation: 52343

As your self-answer notes, this is a known issue. I wanted to point out that it (and other quirks) are documented in the Dalvik docs. You can find it in the official but raw form, or unofficial but formatted -- skip down to "Known Issues and Limitations".

It would be nice if the documentation was more prominent.

Upvotes: 1

dm78
dm78

Reputation: 1600

This is a known issue. It appears that it could be a problem with the Dalvik VM. The last return statement of the method is shown to execute in the debugger.

Changing the doInBackground body to:

        @Override
        protected RequestToken doInBackground( Void... params ) {

            Twitter twitter = getTwitter();
            RequestToken token = null;
            try {
                token = twitter.getOAuthRequestToken();
            }
            catch (TwitterException e) {
                Log.e( TAG, e.getMessage(), e );
            }
            return token;
        }

Causes execution to appear to proceed as expected.

See https://groups.google.com/forum/?fromgroups=#!topic/android-developers/DEU6JmdyFyM for an old mention of the problem with a link to an even older mention. Someone finally created an issue for this at https://code.google.com/p/android/issues/detail?id=34193.

Upvotes: 1

Related Questions