{"record":{"id":"4071e20f3cde8fed","repo":"TheAlgorithms/C-Sharp","slug":"postfix-cannot-be-null-or-empty","errorCode":null,"errorMessage":"Postfix cannot be null or empty.","messagePattern":"Postfix cannot be null or empty\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Stack/InfixToPostfix.cs","lineNumber":192,"sourceCode":"                _ => 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)\n        {\n            if (operatorChar == '^')\n            {\n                return 3;\n            }\n\n            if (operatorChar == '*' || operatorChar == '/')\n            {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Stack/InfixToPostfix.cs#L174-L210","documentation":"InfixToPostfix.ValidatePostfix guards the ConvertToPostfix/Evaluation pipeline by rejecting a null, empty, or whitespace-only postfix expression string. The library throws ArgumentException early so downstream parsing/evaluation code never operates on meaningless input. It is an input-validation failure, not an algorithmic one.","triggerScenarios":"Calling the public postfix evaluation/convert API (via PostfixExpressionEvaluation) with null, \"\", or a string of only spaces/tabs, e.g. PostfixExpressionEvaluation(null) or PostfixExpressionEvaluation(\"   \").","commonSituations":"Reading the expression from a config key, env var, or user textbox that was never filled in; splitting a line of input where the expression column is missing; passing a variable that was declared but never assigned.","solutions":["Ensure the caller supplies a non-empty, non-whitespace postfix expression (e.g. \"3 4 +\") before invoking the API.","Add a guard at the call site: if (string.IsNullOrWhiteSpace(expr)) return/handle before calling PostfixExpressionEvaluation.","If the expression comes from user input or config, validate and prompt/fix the source of the empty value.","Catch ArgumentException if empty input is a legitimate runtime condition and surface a friendly message."],"exampleFix":"// before\nvar result = PostfixExpressionEvaluation(userInput); // userInput may be null/blank\n// after\nvar result = string.IsNullOrWhiteSpace(userInput)\n    ? throw new FormatException(\"Please enter an expression.\")\n    : PostfixExpressionEvaluation(userInput);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(expr))\n{\n    // handle: prompt user, use default, or return early\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var result = PostfixExpressionEvaluation(expr);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Postfix cannot be null or empty\"))\n{\n    // surface a friendly 'expression is required' message\n}","preventionTips":["Always trim and check user/config-supplied expressions before evaluation.","Make input fields required in the UI/form so blank submission is impossible.","Centralize expression reading in one helper that coalesces null to a validated value.","Add unit tests for null/empty/whitespace inputs."],"tags":["argument-validation","null-or-empty","csharp","string-input"],"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-16T04:17:20.429Z"}