{"record":{"id":"9df60bde95a37d7d","repo":"dotnet/machinelearning","slug":"strings-inconsistentnullbitmapandnullcount","errorCode":null,"errorMessage":"Strings.InconsistentNullBitMapAndNullCount","messagePattern":"Strings\\.InconsistentNullBitMapAndNullCount","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs","lineNumber":68,"sourceCode":"            {\n                DataFrameBuffer<T> mutableBuffer = new DataFrameBuffer<T>(length);\n                mutableBuffer.IncreaseSize(length);\n                mutableBuffer.RawSpan.Fill(default(T));\n                dataBuffer = mutableBuffer;\n            }\n            else\n            {\n                dataBuffer = new ReadOnlyDataFrameBuffer<T>(buffer, length);\n            }\n            Buffers.Add(dataBuffer);\n\n            int bitMapBufferLength = (length + 7) / 8;\n            ReadOnlyDataFrameBuffer<byte> nullDataFrameBuffer;\n            if (nullBitMap.IsEmpty)\n            {\n                if (nullCount != 0)\n                {\n                    throw new ArgumentNullException(Strings.InconsistentNullBitMapAndNullCount, nameof(nullBitMap));\n                }\n                if (!buffer.IsEmpty)\n                {\n                    // Create a new bitMap with all the bits up to length set\n                    var bitMap = new DataFrameBuffer<byte>(bitMapBufferLength);\n                    bitMap.IncreaseSize(bitMapBufferLength);\n\n                    var span = bitMap.Span;\n                    span.Fill(255);\n                    int lastByte = 1 << (length - (bitMapBufferLength - 1) * 8);\n                    span[bitMapBufferLength - 1] = (byte)(lastByte - 1);\n\n                    nullDataFrameBuffer = bitMap;\n                }\n                else\n                {\n                    nullDataFrameBuffer = new DataFrameBuffer<byte>();\n                }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs#L50-L86","documentation":"This constructor builds a column from a raw value buffer plus a null bit-map; when the bit-map is empty (IsEmpty) the column must have nullCount == 0, otherwise it throws ArgumentNullException(Strings.InconsistentNullBitMapAndNullCount, nameof(nullBitMap)). 'No bit-map but non-zero null count' is an unverifiable state, so the library refuses it.","triggerScenarios":"Constructing PrimitiveColumnContainer with a buffer plus nullBitMap where nullBitMap.IsEmpty but nullCount > 0 — e.g. passing Memory<byte>.Empty for the bit-map while still reporting nulls.","commonSituations":"Low-level interop or zero-copy code hand-building column buffers; copying column internals and losing the bit-map buffer; optimizations that skip the bit-map but forget to reset nullCount.","solutions":["Provide a real null bit-map buffer when nullCount > 0 (one bit per value, set bit = valid).","If there are no nulls, pass nullCount: 0 alongside the empty bit-map.","Compute nullCount from the bit-map instead of passing a stale value.","Only omit the bit-map when data is guaranteed all-valid."],"exampleFix":"// before\nnew PrimitiveColumnContainer<int>(buffer, Memory<byte>.Empty, nullCount: 3); // throws\n// after\nvar bitMap = BuildBitMap(buffer.Length, nullIndices); // set bits for valid rows\nnew PrimitiveColumnContainer<int>(buffer, bitMap, nullCount: 3);","handlingStrategy":"validation","validationCode":"bool consistent = !nullBitMap.IsEmpty || nullCount == 0;\nif (!consistent) throw new ArgumentException(\"Empty null bit-map requires nullCount == 0\");","typeGuard":"bool isConsistentNullState(ReadOnlyMemory<byte> nullBitMap, long nullCount) =>\n    !nullBitMap.IsEmpty || nullCount == 0;","tryCatchPattern":"try { var c = new PrimitiveColumnContainer<int>(buffer, nullBitMap, nullCount); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"nullBitMap\")\n{ /* bit-map/nullCount mismatch: rebuild bit-map or zero nullCount */ }","preventionTips":["Always build a bit-map when any nulls exist.","Derive nullCount from the bit-map, never hand-set it.","Unit-test low-level buffer construction paths.","Treat empty bit-map as 'all values valid' and keep nullCount at 0."],"tags":["argument-null-exception","null-bitmap","internal-buffer","dataframe"],"backgroundTag":"invalid-argument-value","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}