AlienAsRoger / marketbilling

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

NullPointerException in IabHelper #114

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
STEPS TO REPRODUCE:
1. Call mHelper.queryInventoryAsync(true, skuList, mGotInventoryListener); on 
onIabSetupFinished.  Try/catch surrounding this call does not prevent the ANR.
2. Randomly get NullPointerException thrown by IabHelper

EXPECTED OUTPUT: Should surround queryPurchases and querySkuDetails inside 
IabHelper with try catch NullPointerException blocks so the Exception boils 
back to calling class.  Currently only RemoteException and JSONException are 
being caught, causing NullPointerException to be thrown from IabHelper.

ACTUAL OUTPUT: ANR

OS VERSION: 2.x, 4.x

Exception from coderev 
https://code.google.com/p/marketbilling/source/detail?r=7ec85a9b619fc5f85023bc81
25e7e6b1ab4dd69f:

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

NOTES: See 
http://stackoverflow.com/questions/15456434/billing-api-v3-iabhelper-nullpointer
exception

Original issue reported on code.google.com by appsyna...@gmail.com on 4 Apr 2013 at 7:28

GoogleCodeExporter commented 9 years ago
I ran into this issue too with a Galaxy S3 (android 4.2.2). I think it happens 
when your activity is destroyed and you dispose the IabHelper. As 
queryInventoryAsync runs asynchronously, it doesn't get notified and when it 
tries to access mContext, it throws a NullPointerException.

Solution :
Just add 
"if(mDisposed) return IABHELPER_UNKNOWN_ERROR;"
before 
"// Query purchases
logDebug("Querying owned items, item type: " + itemType);
logDebug("Package name: " + mContext.getPackageName());" line 834.

Original comment by sebastie...@gmail.com on 30 Jun 2013 at 3:53

GoogleCodeExporter commented 9 years ago
Hi Sebastie, sounds good, but: mDisposed does not exist...

Original comment by sleepybu...@gmail.com on 3 Jul 2013 at 9:19

GoogleCodeExporter commented 9 years ago
It does in my version, maybe you should update yours.

Original comment by sebastie...@gmail.com on 3 Jul 2013 at 10:27

GoogleCodeExporter commented 9 years ago
Alright, my bad!

Original comment by sleepybu...@gmail.com on 3 Jul 2013 at 10:35

GoogleCodeExporter commented 9 years ago
Great, hope it helped!

Original comment by sebastie...@gmail.com on 4 Jul 2013 at 12:10

GoogleCodeExporter commented 9 years ago
Thanks, but this is only a workaround. There needs to be a synchronization 
between dispose() and the evaluation of the return value of the service call 
getPurchases().
Maybe using a Handler ?

Original comment by Andreas....@googlemail.com on 16 Jul 2013 at 3:55

GoogleCodeExporter commented 9 years ago
I didn't quite follow your solution sebastian... how do I update my code to get 
the mDiposed boolean?  Is that in a new IABHelper release, or did you create it 
yourself?

Thanks!

Original comment by AndroidD...@gmail.com on 17 Aug 2013 at 7:10

GoogleCodeExporter commented 9 years ago
The mDisposed boolean as been added in the latest releases, udate yours!

Original comment by sebastie...@gmail.com on 19 Aug 2013 at 6:26

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
In latest version there's a method called checkNotDisposed(); that's been used 
in some parts of IabHelper to to the same stuff, so probably we must use it 
here too.

Original comment by dela...@upptalk.com on 14 Jan 2014 at 4:53

GoogleCodeExporter commented 9 years ago
I also see this in the latest (13/12/13) v3 IabHelper

Original comment by smrtprj...@gmail.com on 1 May 2014 at 7:20

GoogleCodeExporter commented 9 years ago
Still see

Original comment by smrtprj...@gmail.com on 11 Oct 2014 at 6:29

GoogleCodeExporter commented 9 years ago
I think I'm seeing the same bug and I just updated my IABHelper code from the 
SDK example 
(android-sdk-macosx/extras/google/play_billing/samples/TrivialDrive/src/com/exam
ple/android/trivialdrivesample/util) a few weeks ago. This is the exception I 
get:

java.lang.NullPointerException
at com.mypackage.IabHelper.queryPurchases(Unknown Source)
at com.mypackage.IabHelper.queryInventory(Unknown Source)
at com.mypackage.IabHelper.queryInventory(Unknown Source)
at com.mypackage.IabHelper$2.run(Unknown Source)
at java.lang.Thread.run(Thread.java:841)

Original comment by car...@instantbits.com on 1 Dec 2014 at 5:00