Class SafeRegex.TimeoutCharSequence

java.lang.Object
org.jline.utils.SafeRegex.TimeoutCharSequence
All Implemented Interfaces:
CharSequence
Enclosing class:
SafeRegex

private static final class SafeRegex.TimeoutCharSequence extends Object implements CharSequence
A CharSequence wrapper that enforces a wall-clock deadline.

The Java regex engine calls charAt(int) for every position it considers during matching. During catastrophic backtracking the call count explodes; we check System.nanoTime() every 1024 calls and throw if the deadline has passed.

The deadline is lazily initialised on the first charAt check so the timeout measures actual matching time, not the gap between Matcher creation and first use. Instances created via subSequence(int, int) share the same deadline array, so the timeout covers the entire matching operation.

  • Field Details

    • inner

      private final CharSequence inner
    • timeoutNanos

      private final long timeoutNanos
    • sharedDeadline

      private final long[] sharedDeadline
      Shared across subSequence(int, int) calls; element 0 holds the deadline (0 = not yet started).
    • calls

      private int calls
  • Constructor Details

    • TimeoutCharSequence

      TimeoutCharSequence(CharSequence inner, long timeoutNanos)
    • TimeoutCharSequence

      private TimeoutCharSequence(CharSequence inner, long timeoutNanos, long[] sharedDeadline)
  • Method Details