Export to GitHub

marketbilling - issue #114

NullPointerException in IabHelper


Posted on Apr 4, 2013 by Happy Horse

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=7ec85a9b619fc5f85023bc8125e7e6b1ab4dd69f:

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-nullpointerexception

Comment #1

Posted on Jun 30, 2013 by Quick Bear

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.

Comment #2

Posted on Jul 3, 2013 by Swift Ox

Hi Sebastie, sounds good, but: mDisposed does not exist...

Comment #3

Posted on Jul 3, 2013 by Quick Bear

It does in my version, maybe you should update yours.

Comment #4

Posted on Jul 3, 2013 by Swift Ox

Alright, my bad!

Comment #5

Posted on Jul 4, 2013 by Quick Bear

Great, hope it helped!

Comment #6

Posted on Jul 16, 2013 by Happy Monkey

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 ?

Comment #7

Posted on Aug 17, 2013 by Quick Rabbit

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!

Comment #8

Posted on Aug 19, 2013 by Quick Bear

The mDisposed boolean as been added in the latest releases, udate yours!

Comment #9

Posted on Oct 27, 2013 by Happy Lion

Comment deleted

Comment #10

Posted on Oct 27, 2013 by Happy Lion

Comment deleted

Comment #11

Posted on Oct 27, 2013 by Happy Lion

Comment deleted

Comment #12

Posted on Jan 14, 2014 by Quick Bear

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.

Comment #13

Posted on May 1, 2014 by Helpful Bird

I also see this in the latest (13/12/13) v3 IabHelper

Comment #14

Posted on Oct 11, 2014 by Helpful Bird

Still see

Comment #15

Posted on Dec 1, 2014 by Happy Monkey

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/example/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)

Comment #16

Posted on Aug 9, 2015 by Happy Wombat

Comment deleted

Comment #17

Posted on Aug 9, 2015 by Happy Wombat

Comment deleted

Comment #18

Posted on Aug 9, 2015 by Happy Hippo

Thanks Sebastie...Solution worked.

Status: New

Labels:
Type-Defect Priority-Medium