cloudfoundry/go-cfclient

Panic when ListOptions is nil

Closed this issue · 1 comments

This code will cause panic when more then 1 page of results returned

      listOpts := &cf.ServicePlanListOptions{
		ServiceBrokerNames: cf.Filter{
			Values: []string{"broker_name"},
		},
	}

	clPlans, clOfferings, err := client.ServicePlans.ListIncludeServiceOfferingAll(ctx, listOpts)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x100638270]

goroutine 1 [running]:
github.com/cloudfoundry-community/go-cfclient/v3/client.(*ListOptions).CurrentPage(0x1400036a120?, 0x10071b487?, 0x14000088000?)
        /Users/igera/Go/pkg/mod/github.com/cloudfoundry-community/go-cfclient/v3@v3.0.0-alpha.4/client/list_opt.go:48
github.com/cloudfoundry-community/go-cfclient/v3/client.(*Pager).NextPage(0x14000040040, {0x1008dfac8, 0x140000cc280})
        /Users/igera/Go/pkg/mod/github.com/cloudfoundry-community/go-cfclient/v3@v3.0.0-alpha.4/client/pager.go:47 +0xb8
github.com/cloudfoundry-community/go-cfclient/v3/client.(*ServicePlanClient).ListIncludeServiceOfferingAll(0x140000aa070?, {0x1008e16b0, 0x1400019a008}, 0x0?)
        /Users/igera/Go/pkg/mod/github.com/cloudfoundry-community/go-cfclient/v3@v3.0.0-alpha.4/client/service_plan.go:144 +0xc8

sneal commented

You can use client.NewServicePlanListOptions() so that the embedded ListOptions struct is populated like so:

opts := client.NewServicePlanListOptions()
opts.ServiceBrokerNames.EqualTo("broken_name")
clPlans, clOfferings, err := cf.ServicePlans.ListIncludeServiceOfferingAll(ctx, opts)