{"record":{"id":"429481f86d612b09","repo":"hyperledger/fabric","slug":"nil-data","errorCode":null,"errorMessage":"nil data","messagePattern":"nil data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/cdspackage.go","lineNumber":149,"sourceCode":"\n\t// compute the id\n\thash.Write(cdsdata.CodeHash)\n\thash.Write(cdsdata.MetaDataHash)\n\n\tid := hash.Sum(nil)\n\n\treturn b, id, cdsdata, nil\n}\n\n// ValidateCC returns error if the chaincode is not found or if its not a\n// ChaincodeDeploymentSpec\nfunc (ccpack *CDSPackage) ValidateCC(ccdata *ChaincodeData) error {\n\tif ccpack.depSpec == nil {\n\t\treturn errors.New(\"uninitialized package\")\n\t}\n\n\tif ccpack.data == nil {\n\t\treturn errors.New(\"nil data\")\n\t}\n\n\t// This is a hack. LSCC expects a specific LSCC error when names are invalid so it\n\t// has its own validation code. We can't use that error because of import cycles.\n\t// Unfortunately, we also need to check if what have makes some sort of sense as\n\t// protobuf will gladly deserialize garbage and there are paths where we assume that\n\t// a successful unmarshal means everything works but, if it fails, we try to unmarshal\n\t// into something different.\n\tif !isPrintable(ccdata.Name) {\n\t\treturn fmt.Errorf(\"invalid chaincode name: %q\", ccdata.Name)\n\t}\n\n\tif ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {\n\t\treturn fmt.Errorf(\"invalid chaincode data %v (%v)\", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)\n\t}\n\n\totherdata := &CDSData{}\n\terr := proto.Unmarshal(ccdata.Data, otherdata)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/cdspackage.go#L131-L167","documentation":"ValidateCC checks ccpack.data (the hashed CDSData) and returns 'nil data' when it is nil. Like the uninitialized depSpec check, this means the package was not fully initialized — the data hash computed by getCDSData is missing — so the package cannot be validated against ChaincodeData.","triggerScenarios":"Calling ValidateCC on a CDSPackage where depSpec was set but data was never computed — e.g. partially constructed package, or a package whose getCDSData step was skipped/failed silently.","commonSituations":"Manually assembled CDSPackage in tests; partially completed initialization after a swallowed error; deserialization paths that set depSpec but not data.","solutions":["Initialize the package fully via InitFromBuffer or InitFromPath so getCDSData populates data","Check the error from the initialization call before calling ValidateCC","Do not manually set depSpec without running getCDSData / SetChaincodeData"],"exampleFix":"// before\nccpack.depSpec = depSpec // set directly, data left nil\nccpack.ValidateCC(ccdata)\n// after\nccpack := &CDSPackage{}\nccpack.InitFromBuffer(buf) // populates depSpec, data, id\nccpack.ValidateCC(ccdata)","handlingStrategy":"validation","validationCode":"// ensure full init so internal data hash is populated\nif _, err := ccpack.InitFromBuffer(buf); err != nil {\n    return fmt.Errorf(\"cannot validate: package data not initialized: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := ccpack.ValidateCC(ccdata); err != nil {\n    switch err.Error() {\n    case \"uninitialized package\", \"nil data\":\n        return fmt.Errorf(\"package not initialized before validation: %w\", err)\n    }\n    return err\n}","preventionTips":["Initialize packages only via InitFromBuffer/InitFromPath","Handle init errors immediately; never ignore-and-continue","Avoid reaching into struct fields to half-populate packages","Cover init+validate in tests so partial init surfaces early"],"tags":["hyperledger-fabric","chaincode","nil","initialization"],"backgroundTag":"nil-field-validation","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}