{"record":{"id":"78387f8916b0d289","repo":"TheAlgorithms/C-Sharp","slug":"infix-cannot-be-null-or-empty","errorCode":null,"errorMessage":"Infix cannot be null or empty.","messagePattern":"Infix cannot be null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Stack/InfixToPostfix.cs","lineNumber":184,"sourceCode":"\n            int result = op switch\n            {\n                '+' => a + b,\n                '-' => a - b,\n                '*' => a * b,\n                '/' => a / b,\n                '^' => (int)Math.Pow(a, b),\n                _ => throw new InvalidOperationException($\"Unknown operator {op}\"),\n            };\n\n            stack.Push(result);\n        }\n\n        private static void ValidateInfix(string expr)\n        {\n            if (string.IsNullOrEmpty(expr) || string.IsNullOrWhiteSpace(expr))\n            {\n                throw new ArgumentException(\"Infix cannot be null or empty.\");\n            }\n        }\n\n        private static void ValidatePostfix(string expr)\n        {\n            if (string.IsNullOrEmpty(expr) || string.IsNullOrWhiteSpace(expr))\n            {\n                throw new ArgumentException(\"Postfix cannot be null or empty.\");\n            }\n        }\n\n        /// <summary>\n        /// Decided Operator Precedence.\n        /// <param name=\"operatorChar\"> Operator character whose precedence is asked.</param>\n        /// <returns>Precedence rank of parameter operator character.</returns>\n        /// </summary>\n        [ExcludeFromCodeCoverage]\n        private static int Precedence(char operatorChar)","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Stack/InfixToPostfix.cs#L166-L202","documentation":"ValidateInfix is a private guard called by InfixToPostfixConversion; it throws ArgumentException when the infix expression string is null, empty, or whitespace-only, since there is nothing to convert.","triggerScenarios":"Calling InfixToPostfixConversion(null), InfixToPostfixConversion(\"\"), or InfixToPostfixConversion(\"   \").","commonSituations":"Configuration values or user input fields left blank; upstream methods returning null that are passed straight through.","solutions":["Check string.IsNullOrWhiteSpace(expr) before calling InfixToPostfixConversion and skip or prompt for input.","Provide a default expression when the input is empty.","Catch ArgumentException and surface a 'please enter an expression' message."],"exampleFix":"// before\nstring postfix = converter.InfixToPostfixConversion(userInput);\n// after\nif (!string.IsNullOrWhiteSpace(userInput))\n{\n    string postfix = converter.InfixToPostfixConversion(userInput);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(infix)) return null; // or prompt for input before converting","typeGuard":"bool HasInfix(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { var postfix = converter.InfixToPostfixConversion(infix); } catch (ArgumentException) { /* treat empty input as no-op / user prompt */ }","preventionTips":["Coalesce null/empty inputs to a default or early-return","Validate user input at the boundary before conversion","Trim whitespace-only values in configuration"],"tags":["null","empty","validation"],"backgroundTag":"empty-required-field","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}