{"record":{"id":"48042fc7fe777d86","repo":"TheAlgorithms/C-Sharp","slug":"x-has-no-value","errorCode":null,"errorMessage":"x has no value","messagePattern":"x has no value","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs","lineNumber":232,"sourceCode":"\n    /// <summary>\n    ///     Reduce the key of x to be k.\n    /// </summary>\n    /// <remarks>\n    ///     k must be less than x.Key, increasing the key of an item is not supported.\n    /// </remarks>\n    /// <param name=\"x\">The item you want to reduce in value.</param>\n    /// <param name=\"k\">The new value for the item.</param>\n    public void DecreaseKey(FHeapNode<T> x, T k)\n    {\n        if (MinItem == null)\n        {\n            throw new ArgumentException($\"{nameof(x)} is not from the heap\");\n        }\n\n        if (x.Key == null)\n        {\n            throw new ArgumentException(\"x has no value\");\n        }\n\n        if (k.CompareTo(x.Key) > 0)\n        {\n            throw new InvalidOperationException(\"Value cannot be increased\");\n        }\n\n        x.Key = k;\n        var y = x.Parent;\n        if (y != null && x.Key.CompareTo(y.Key) < 0)\n        {\n            Cut(x, y);\n            CascadingCut(y);\n        }\n\n        if (x.Key.CompareTo(MinItem.Key) < 0)\n        {\n            MinItem = x;","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/DataStructures/Heap/FibonacciHeap/FibonacciHeap.cs#L214-L250","documentation":"FibonacciHeap.DecreaseKey throws ArgumentException \"x has no value\" when the node's Key is null. DecreaseKey must compare the new value k against the existing key, which is impossible when the stored key is null.","triggerScenarios":"DecreaseKey on a node whose Key property is null (e.g. a detached or default-constructed FHeapNode<T> with a nullable/uninitialized key).","commonSituations":"Using reference-type T where nodes were created without assigning Key, or reusing nodes after removal that reset their key.","solutions":["Ensure the node was Push()ed onto the heap so its Key is assigned.","Check x.Key != null before calling DecreaseKey().","Avoid reusing node objects after they are popped."],"exampleFix":"// before\nheap.DecreaseKey(node, k); // node.Key == null\n// after\nif (node.Key != null)\n{\n    heap.DecreaseKey(node, k);\n}","handlingStrategy":"type-guard","validationCode":"if (node.Key != null) { heap.DecreaseKey(node, k); }","typeGuard":"bool HasKey(FHeapNode<T> node) => node.Key is not null;","tryCatchPattern":"try { heap.DecreaseKey(node, k); } catch (ArgumentException) { /* node key null / not in heap */ }","preventionTips":["Always Push nodes so their Key is initialized","Do not reuse detached nodes","With nullable T, validate Key before operations that compare it"],"tags":["data-structures","fibonacci-heap","null"],"backgroundTag":"null-argument","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"}