antlr/antlr4 · error · ArgumentOutOfRangeException

index

Error message

index

What it means

Error "index" thrown in antlr/antlr4.

Source

Thrown at runtime/CSharp/src/Sharpen/BitSet.cs:121

        {
            if (value == 0)
                return -1;

            const ulong debruijn64 = 0x03f79d71b4cb0a89;
            return index64[((value ^ (value - 1)) * debruijn64) >> 58];
        }

        public BitSet Clone()
        {
            BitSet result = new BitSet();
            result._data = (ulong[])_data.Clone();
            return result;
        }

        public void Clear(int index)
        {
            if (index < 0)
                throw new ArgumentOutOfRangeException("index");

            int element = index / BitsPerElement;
            if (element >= _data.Length)
                return;

            _data[element] &= ~(1UL << (index % BitsPerElement));
        }

		public bool this[int index]
		{
			get
			{
				return Get(index);
			}
			set
			{
				Set(index);
			}

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Pass a non-negative index to the BitSet operation; clamp or validate the index at the call site.
  2. Check index >= 0 && index < Capacity before Get/Set.

Example fix

if (index >= 0) bits.Set(index, true);

When it happens

Trigger: BitSet.Get/Set/Clear called with a negative index.

Common situations: Validate bit index >= 0 before BitSet operations.


AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14). Data as JSON: /api/errors/1f5bec4b157e3ff3. Report an issue: GitHub.