12

My app silently crashes (no force close popup) when i try to set a cookie on the cookiemanager.

mHttpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
HttpGet http_get = new HttpGet(url); 
HttpResponse response = mHttpClient.execute(http_get);

for(Cookie cookie : mHttpClient.getCookieStore().getCookies()) {

    Log.d(AppPreferences.TESTTAG,"cookie =  " + cookie.getName());
    if(cookie.getName().equals("SACSID") || cookie.getName().equals("ACSID"))
    {
        response.getEntity().consumeContent();
        String cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain();  
        CookieManager.getInstance().setCookie(cookie.getDomain(), cookieString); //**crashes here**
        return true;
    }                   
}

Here's all i'm getting from logcat

04-19 22:51:35.277: W/dalvikvm(16704): Invalid indirect reference 0x414bb040 in decodeIndirectRef
04-19 22:51:35.277: E/dalvikvm(16704): VM aborting
04-19 22:51:35.281: A/libc(16704): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 16754 (AsyncTask #1)

Here's the tombstone log generated: http://textuploader.com/?p=6&id=gPpJ

It fails right on the CookieManager setCookie() line (i.e. I log a message before and after that line it prints the before message but not the one after)

Anyone run in to this problem?

user2128112
  • 299
  • 4
  • 13

3 Answers3

27

Add CookieSyncManager.createInstance(context); before calling CookieManager.

Phil
  • 1,200
  • 13
  • 17
2

Try to create WebView in onCreate() method and destroy it. WebView create some "bridge" between ContentManager and WebKit. Some thing like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_layout);
    WebView web = new WebView(this);
    web.destroy();
}
Dmitry Velychko
  • 1,505
  • 16
  • 14
0

If you are completely certain that this crash is triggered by the code you have above, this represents a firmware bug. There's no way an Android SDK app should be able to trigger a SIGSEGV.

If this occurs on a Nexus device, on the emulator, or across multiple devices, it is probably an Android bug. File an issue on http://b.android.com (if there doesn't appear to be one already), pointing to this issue and probably attaching that tombstone log.

If this occurs only in some specific setting (e.g., one device, one ROM mod) and not others, it is probably something peculiar to that environment, in which case you should try to get help from the device or ROM mod maker.

Beyond that, make sure that cookie.getDomain() is returning a valid value, as, off the cuff, that seems like the most likely culprit.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491