{"record":{"id":"38710102e6982828","repo":"AvaloniaUI/Avalonia","slug":"either-e-or-container-must-be-non-null","errorCode":null,"errorMessage":"Either 'e' or 'container' must be non-null.","messagePattern":"Either 'e' or 'container' must be non-null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Input/Navigation/TabNavigation.cs","lineNumber":92,"sourceCode":"            }\n\n            return null;\n        }\n\n        public static IInputElement? GetNextTabOutside(ICustomKeyboardNavigation e)\n        {\n            if (e is IInputElement container && GetLastInTree(container) is { } last)\n            {\n                return GetNextTab(last, false);\n            }\n\n            return null;\n        }\n\n        public static IInputElement? GetPrevTab(IInputElement? e, IInputElement? container, bool goDownOnly)\n        {\n            container ??=\n                GetGroupParent(e ?? throw new InvalidOperationException(\"Either 'e' or 'container' must be non-null.\"));\n\n            KeyboardNavigationMode tabbingType = GetKeyNavigationMode(container);\n\n            if (e == null)\n            {\n                // Using ActiveElement if set\n                var activeElement = GetActiveElement(container);\n                if (activeElement != null)\n                    return GetPrevTab(null, activeElement, true);\n                else\n                {\n                    // If we Shift+Tab on a container with KeyboardNavigationMode=Once, and ActiveElement is null\n                    // then we want to go to the first item (not last) within the container\n                    if (tabbingType == KeyboardNavigationMode.Once)\n                    {\n                        var firstTabElement = GetNextTabInGroup(null, container, tabbingType);\n                        if (firstTabElement == null)\n                        {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Input/Navigation/TabNavigation.cs#L74-L110","documentation":"TabNavigation.GetPrevTab derives the container (group parent) from the element `e` when a container is not supplied. If both `e` and `container` are null there is no way to find the tab group, so it throws InvalidOperationException to fail fast on an unresolvable call.","triggerScenarios":"Calling `TabNavigation.GetPrevTab(null, null, goDownOnly)` — no element and no container provided.","commonSituations":"Passing two nulls by accident from nullable variables. A caller computing `e` and `container` that both resolve to null (e.g. focus not set, parent not found).","solutions":["Provide at least one non-null argument: the focused element or the tab container.","Guard before calling: `if (e is null && container is null) return null;`.","Ensure the element is in the logical tree so a container can be derived."],"exampleFix":"// before:\nvar next = TabNavigation.GetPrevTab(null, null, false); // throws\n\n// after:\nif (e is null && container is null) return null;\nvar next = TabNavigation.GetPrevTab(e, container, false);","handlingStrategy":"validation","validationCode":"if (e is null && container is null) return null;\nreturn TabNavigation.GetPrevTab(e, container, goDownOnly);","typeGuard":"static bool HasTarget(IInputElement? e, IInputElement? c) => e is not null || c is not null;","tryCatchPattern":null,"preventionTips":["Provide at least one of element or container.","Null-guard both arguments before calling.","Ensure the element is in the logical tree so a container resolves."],"tags":["tabnavigation","focus","navigation","invalidoperation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}