{"record":{"id":"a38fd2f2f6774d74","repo":"apache/beam","slug":"broken-invariant-idsfound-map-is-nil-but-idsrequired-map","errorCode":null,"errorMessage":"broken invariant: idsFound map is nil, but idsRequired map exists","messagePattern":"broken invariant: idsFound map is nil, but idsRequired map exists","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/util/starcgenx/starcgenx.go","lineNumber":333,"sourceCode":"func (v findRegisterDoFnCalls) findPackageRename(iden *ast.Ident) *types.PkgName {\n\tfor k, imp := range v.info.Defs {\n\t\tif k.Name == iden.Name {\n\t\t\tif pkgName, ok := imp.(*types.PkgName); ok {\n\t\t\t\tv.e.Printf(\"\\tfound package rename %#v  -  %v\\n\", k, types.ObjectString(imp, nil))\n\t\t\t\treturn pkgName\n\t\t\t}\n\t\t}\n\t}\n\tv.e.Printf(\"\\tfail - %v not a package\\n\", types.ExprString(iden))\n\treturn nil\n}\n\nfunc (e *Extractor) isRequired(ident string, obj types.Object, idsRequired, idsFound map[string]bool) bool {\n\tif idsRequired == nil {\n\t\treturn true\n\t}\n\tif idsFound == nil {\n\t\tpanic(\"broken invariant: idsFound map is nil, but idsRequired map exists\")\n\t}\n\t// If we're filtering IDs, then it needs to be in the filtered identifiers,\n\t// or it's receiver type identifier needs to be in the filtered identifiers.\n\tif idsRequired[ident] {\n\t\tidsFound[ident] = true\n\t\te.Printf(\"isRequired found: %s\\n\", ident)\n\t\treturn true\n\t}\n\t// Check if this is a function.\n\tsig, ok := obj.Type().(*types.Signature)\n\tif !ok {\n\t\treturn false\n\t}\n\t// If this is a function, and it has a receiver, it's a method.\n\tif recv := sig.Recv(); recv != nil && graph.IsLifecycleMethod(ident) {\n\t\t// We don't want to care about pointers, so dereference to value type.\n\t\tt := recv.Type()\n\t\tp, ok := types.Unalias(t).(*types.Pointer)","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/util/starcgenx/starcgenx.go#L315-L351","documentation":"starcgenx's Extractor.isRequired enforces that when an explicit list of required identifiers (idsRequired) is provided, the companion idsFound map must also exist, since found identifiers are recorded into it. If idsFound is nil while idsRequired is set, the internal contract is violated and the code panics with this invariant message. This indicates a programming bug in the caller (fromObj), not user input.","triggerScenarios":"Calling Extractor.fromObj (or isRequired) with idsRequired non-nil and idsFound nil — i.e. an inconsistent internal call path in starcgenx, typically after a code change to fromObj's filtering logic.","commonSituations":"Editing or extending starcgenx's identifier-filtering code and passing mismatched map arguments; running a broken or patched build of the xlang stub generator.","solutions":["Fix the caller (fromObj) so idsFound is always a non-nil, initialized map whenever idsRequired is non-nil.","Pass the same idsFound map consistently through all isRequired calls in one extraction run.","Pin to an unmodified upstream Beam release if a local patch introduced the bug.","Report the invariant violation upstream with the generator invocation if it reproduces on stock code."],"exampleFix":"// before\nvar idsFound map[string]bool\ne.isRequired(ident, obj, idsRequired, idsFound)\n// after\nidsFound := map[string]bool{}\ne.isRequired(ident, obj, idsRequired, idsFound)","handlingStrategy":"validation","validationCode":"if idsRequired != nil && idsFound == nil {\n    return fmt.Errorf(\"idsFound must be initialized when idsRequired is set\")\n}","typeGuard":"func mapsConsistent(idsRequired, idsFound map[string]bool) bool {\n    return idsRequired == nil || idsFound != nil\n}","tryCatchPattern":null,"preventionTips":["Always initialize idsFound with make(map[string]bool) when filtering IDs","Keep idsRequired and idsFound paired in a small struct","Add unit tests covering the filtered-extraction path","Avoid local patches to starcgenx internals"],"tags":["go","panic","invariant","code-generation"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}