{"record":{"id":"3401fde3edeed2a8","repo":"goharbor/harbor","slug":"the-resource-cannot-be-null-3401fd","errorCode":null,"errorMessage":"the resource cannot be null","messagePattern":"the resource cannot be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/reg/adapter/jfrog/adapter.go","lineNumber":120,"sourceCode":"\t\t},\n\t}\n\treturn\n}\n\nfunc newAdapter(registry *model.Registry) (adp.Adapter, error) {\n\treturn &adapter{\n\t\tAdapter:  native.NewAdapter(registry),\n\t\tregistry: registry,\n\t\tclient:   newClient(registry),\n\t}, nil\n}\n\n// PrepareForPush creates local docker repository in jfrog artifactory\nfunc (a *adapter) PrepareForPush(resources []*model.Resource) error {\n\tvar namespaces []string\n\tfor _, resource := range resources {\n\t\tif resource == nil {\n\t\t\treturn errors.New(\"the resource cannot be null\")\n\t\t}\n\t\tif resource.Metadata == nil {\n\t\t\treturn errors.New(\"the metadata of resource cannot be null\")\n\t\t}\n\t\tif resource.Metadata.Repository == nil {\n\t\t\treturn errors.New(\"the namespace of resource cannot be null\")\n\t\t}\n\t\tif len(resource.Metadata.Repository.Name) == 0 {\n\t\t\treturn errors.New(\"the name of namespace cannot be null\")\n\t\t}\n\t\tpath := strings.Split(resource.Metadata.Repository.Name, \"/\")\n\t\tif len(path) > 0 {\n\t\t\tnamespaces = append(namespaces, path[0])\n\t\t}\n\t}\n\n\trepositories, err := a.listAllRepositories()\n\tif err != nil {","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/pkg/reg/adapter/jfrog/adapter.go#L102-L138","documentation":"Returned by the JFrog Artifactory adapter's PrepareForPush (src/pkg/reg/adapter/jfrog/adapter.go:120), which pre-creates local docker repositories in Artifactory before images are pushed. The loop over resources rejects any element that is a nil *model.Resource. It throws early because later code dereferences resource.Metadata unconditionally.","triggerScenarios":"Calling PrepareForPush on the jfrog adapter with a nil element in the []*model.Resource slice, e.g. append(resources, nil) or a filter step that leaves nil placeholders.","commonSituations":"Custom transfer pipelines that append nil when an intermediate fetch fails instead of aborting; refactoring that introduces sparse slices; copy between registries where one artifact's metadata build failed silently.","solutions":["Find where the resource slice is built and stop appending nil entries — fail the fetch instead of inserting nil.","Sanitize the slice before the call (see validationCode) so the offending index is reported.","If a nil entry is legitimate 'skip' semantics in your code, filter it out before calling PrepareForPush.","Upgrade/review your caller: upstream Harbor always passes fully-formed resources, so a nil element indicates a local bug."],"exampleFix":"// before\nfor _, r := range fetched {\n    if r == nil {\n        resources = append(resources, nil) // placeholder, panics later or errors here\n    } else {\n        resources = append(resources, r)\n    }\n}\n\n// after\nfor _, r := range fetched {\n    if r == nil {\n        return fmt.Errorf(\"fetch returned a nil resource\")\n    }\n    resources = append(resources, r)\n}","handlingStrategy":"validation","validationCode":"for i, r := range resources {\n\tif r == nil {\n\t\treturn fmt.Errorf(\"resources[%d] is nil; refusing to call PrepareForPush\", i)\n\t}\n}\nif err := jfrogAdapter.PrepareForPush(resources); err != nil { /* ... */ }","typeGuard":"func isUsableResource(r *model.Resource) bool { return r != nil }","tryCatchPattern":"if err := a.PrepareForPush(resources); err != nil {\n\tif strings.Contains(err.Error(), \"the resource cannot be null\") {\n\t\t// slice construction bug: log index and rebuild resources\n\t}\n\treturn err\n}","preventionTips":["Filter or reject nil entries when assembling the slice.","Fail the whole transfer when any fetch returns nil rather than inserting placeholders.","Lint for 'append(resources, nil)' patterns in review."],"tags":["go","jfrog","artifactory","replication","validation","nil-check"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}