[ https://issues.apache.org/jira/browse/YUNIKORN-952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17448049#comment-17448049 ]
Wilfred Spiegelenburg commented on YUNIKORN-952: ------------------------------------------------ It would be far easier to not specify a capacity and let the system handle the allocation of the array and re-slice. Append has logic build in to re-allocate if the array is not big enough. Simply initialising the slice via: {code:java} appList := make([]*objects.Application, 0){code} The other thing is relying on the fact that you can append to a nil slice: {code:java} var appList []*objects.Application appList = append(appList, partition.GetApplications()...) {code} > nil pointer error in webservice.getApplicationJSON() > ---------------------------------------------------- > > Key: YUNIKORN-952 > URL: https://issues.apache.org/jira/browse/YUNIKORN-952 > Project: Apache YuniKorn > Issue Type: Bug > Components: core - scheduler > Reporter: Peter Bacsko > Assignee: Peter Bacsko > Priority: Major > Labels: pull-request-available > > The implementation of the new method {{getApplicationsDAO()}} is incorrect: > {noformat} > func getApplicationsDAO(lists map[string]*scheduler.PartitionContext) > []*dao.ApplicationDAOInfo { > result := make([]*dao.ApplicationDAOInfo, 0, 32) > for _, partition := range lists { > size := partition.GetTotalCompletedApplicationCount() + > partition.GetTotalApplicationCount() > appList := make([]*objects.Application, size) > appList = append(appList, partition.GetApplications()...) > appList = append(appList, > partition.GetCompletedApplications()...) > .... > {noformat} > The slice creation is incorrect - the initial length should be 0, and the > capacity should be set to the "size": > {noformat} > appList := make([]*objects.Application, 0, size) > {noformat} > Right now appList will contail "nil" elements after creation: > {noformat} > goroutine 847 [running]: > net/http.(*conn).serve.func1() > /snap/go/8627/src/net/http/server.go:1801 +0xb9 > panic({0x14c04e0, 0x2476930}) > /snap/go/8627/src/runtime/panic.go:1047 +0x266 > github.com/apache/incubator-yunikorn-core/pkg/scheduler/objects.(*Application).GetAllAllocations(0xffffffffffffffff) > > /home/bacskop/repos/yunikorn-core/pkg/scheduler/objects/application.go:1134 > +0x51 > github.com/apache/incubator-yunikorn-core/pkg/webservice.getApplicationJSON(0x0) > /home/bacskop/repos/yunikorn-core/pkg/webservice/handlers.go:250 +0x36 > github.com/apache/incubator-yunikorn-core/pkg/webservice.getApplicationsDAO(0xc006916270) > /home/bacskop/repos/yunikorn-core/pkg/webservice/handlers.go:632 +0x313 > github.com/apache/incubator-yunikorn-core/pkg/webservice.doStateDump({0x188dee0, > 0xc0002400e0}) > /home/bacskop/repos/yunikorn-core/pkg/webservice/state_dump.go:143 > +0x158 > github.com/apache/incubator-yunikorn-core/pkg/webservice.getFullStateDump({0x18b5138, > 0xc0002400e0}, 0x489bf7) > /home/bacskop/repos/yunikorn-core/pkg/webservice/state_dump.go:67 +0x45 > net/http.HandlerFunc.ServeHTTP(0x100000000000000, {0x18b5138, 0xc0002400e0}, > 0x90) > /snap/go/8627/src/net/http/server.go:2046 +0x2f > {noformat} -- This message was sent by Atlassian Jira (v8.20.1#820001) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@yunikorn.apache.org For additional commands, e-mail: issues-h...@yunikorn.apache.org