braintree / braintree_java

Braintree Java library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
158 stars 98 forks source link

Possible NullPointerException during UsBankAccount instantiation #61

Closed kmichalak closed 6 years ago

kmichalak commented 6 years ago

General information

Possible NullPointerException during UsBankAccount instantiation

I have found that constructor of the class com.braintreegateway.UsBankAccount adds subscription objects to an uninitialized list

public UsBankAccount(NodeWrapper node) {
    this.routingNumber= node.findString("routing-number");
    this.last4 = node.findString("last-4");
    this.accountType = node.findString("account-type");
    this.accountHolderName = node.findString("account-holder-name");
    this.token = node.findString("token");
    this.imageUrl = node.findString("image-url");
    this.bankName = node.findString("bank-name");
    for (NodeWrapper subscriptionResponse : node.findAll("subscriptions/subscription")) {
       // Here is the place where NullPointerException can be thrown
        this.subscriptions.add(new Subscription(subscriptionResponse));
    }
    this.customerId = node.findString("customer-id");
    this.isDefault = node.findBoolean("default");
    this.achMandate = new AchMandate(node.findFirst("ach-mandate"));
}

In other places, like CoinbaseAccount, a for-loop is proceded with list initialization like this

this.subscriptions = new ArrayList<Subscription>();
jaypatel512 commented 6 years ago

You are absolutely right @kmichalak ! We will add that fix right away. Good catch.

jaypatel512 commented 6 years ago

Hey @kmichalak ! The fix has been released in v2.77.0. Thank you so much for pointing that out. 🎆