xonglennao / marketbilling

Automatically exported from code.google.com/p/marketbilling
0 stars 0 forks source link

java.lang.IllegalStateException: IabHelper was disposed of, so it cannot be used. #146

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
STEPS TO REPRODUCE:
- race condition, cannot easily reproduce

ACTUAL OUTPUT:
crashes with exception in checkNotDisposed()

NOTES:
There seem to be race conditions with background threads in IabHelper.
I got crash reports saying:
java.lang.IllegalStateException: IabHelper was disposed of, so it cannot be 
used.
at xxx.iab.IabHelper.checkNotDisposed(SourceFile:302)
at xxx.iab.IabHelper.queryInventory(SourceFile:540)
at xxx.iab.IabHelper.queryInventory(SourceFile:522)
at xxx.iab.IabHelper$2.run(SourceFile:617)
at java.lang.Thread.run(Thread.java:856)

The problem seems to be that when queryInventoryAsync() is called, the 
checkNotDisposed() in line 609 is still ok. However, in the background thread 
that is started right after it, checkNotDisposed() fails. That means the code 
does not consider IabHelper do be disposed just before the background thread 
starts to run.

A quick fix is to check mDisposed at the beginning of the background thread and 
return if disposed. However, there are more race conditions in the code, like:

java.lang.NullPointerException
at xxx.iab.IabHelper.queryPurchases(SourceFile:836)
at xxx.iab.IabHelper.queryInventory(SourceFile:558)
at xxx.iab.IabHelper.queryInventory(SourceFile:522)
at xxx.iab.IabHelper$2.run(SourceFile:617)
at java.lang.Thread.run(Thread.java:1019)

This all appears to be a flaw in the code with background thread in conjunction 
with IabHelper disposal.

Original issue reported on code.google.com by dirk.fa...@gmail.com on 19 Sep 2013 at 3:50

GoogleCodeExporter commented 8 years ago
Got the same problem here sometimes.
Please fix!

Original comment by ti08m...@gmail.com on 18 Jan 2014 at 9:22

GoogleCodeExporter commented 8 years ago
Facing same issue.
java.lang.IllegalStateException: IabHelper was disposed of, so it cannot be 
used.
       at com.android.vending.billing.library.IabHelper.checkNotDisposed(IabHelper.java:297)
       at com.android.vending.billing.library.IabHelper.queryInventory(IabHelper.java:548)
       at com.android.vending.billing.library.IabHelper.queryInventory(IabHelper.java:527)
       at com.android.vending.billing.library.IabHelper$2.run(IabHelper.java:626)
       at java.lang.Thread.run(Thread.java:856)

please any fix for it.

Original comment by bipinva...@gmail.com on 14 Feb 2014 at 9:02

GoogleCodeExporter commented 8 years ago
I had crashes with the same error message on activity startup. Managed to stop 
receiving them with (pseudocode follows)

public void init(){
    if(mIabHelper == null){         
        mIabHelper = new IabHelper(mContext, "PUBLIC_KEY_FROM_DEV_CONSOLE");        
        mIabHelper.startSetup(...);

        mContext.bindService(...);
    }
}

public void close(){
    if( mIabHelper != null ){
        mIabHelper.dispose();
            mIabHelper = null;
        }

        mContext.unbindService(...);        
}

// Then in My Activity class:

public void onCreate(...){
    //...
    init();
}

public void onDestroy(){
    // ...
    close();
}

Don't know if it's the most elegant solution, but in my case it worked. Hope it 
helps

Original comment by olmo...@gmail.com on 10 Mar 2014 at 9:16

GoogleCodeExporter commented 8 years ago
We've received few crash reports for this issue. checkNotDisposed() is being 
used in multiple methods. Please fix it.

Original comment by glovant...@gmail.com on 18 Apr 2014 at 6:44