{"record":{"id":"31fc90d4aaa19c7f","repo":"antlr/antlr4","slug":"nbits","errorCode":null,"errorMessage":"nbits","messagePattern":"nbits","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"runtime/CSharp/src/Sharpen/BitSet.cs","lineNumber":24,"sourceCode":"{\n    using System;\n    using System.Text;\n\n    public class BitSet\n    {\n        private static readonly ulong[] EmptyBits = Collections.EmptyList<ulong>();\n        private const int BitsPerElement = 8 * sizeof(ulong);\n\n        private ulong[] _data = EmptyBits;\n\n        public BitSet()\n        {\n        }\n\n        public BitSet(int nbits)\n        {\n            if (nbits < 0)\n                throw new ArgumentOutOfRangeException(\"nbits\");\n\n            if (nbits > 0)\n            {\n                int length = (nbits + BitsPerElement - 1) / BitsPerElement;\n                _data = new ulong[length];\n            }\n        }\n\n        private static int GetBitCount(ulong[] value)\n        {\n            int data = 0;\n            uint size = (uint)value.Length;\n            const ulong m1 = 0x5555555555555555;\n            const ulong m2 = 0x3333333333333333;\n            const ulong m4 = 0x0F0F0F0F0F0F0F0F;\n            const ulong m8 = 0x00FF00FF00FF00FF;\n            const ulong m16 = 0x0000FFFF0000FFFF;\n            const ulong h01 = 0x0101010101010101;","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Sharpen/BitSet.cs#L6-L42","documentation":"Error \"nbits\" thrown in antlr/antlr4.","triggerScenarios":"BitSet constructed with a negative nbits argument.","commonSituations":"Pass a non-negative bit count when constructing Sharpen.BitSet.","solutions":["Pass a non-negative bit count when constructing the BitSet.","Validate the size parameter before allocating the set."],"exampleFix":"var bits = new BitSet(64);","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}