stanfordnlp/CoreNLP · error · RuntimeException

begin and end are equal

Error message

begin and end are equal ${this}

What it means

While expanding a duration of the form P##Y (years) relative to a document time, Timex.getRange computes start = docTime - N years and end = docTime; if the parsed yearRange is 0 it throws RuntimeException 'begin and end are equal'. A zero-width range is considered a bug/invalid input rather than a valid point.

Solutions

  1. Fix upstream annotation/normalization so P0Y durations are not produced
  2. Treat P0Y as a point: use documentTime.getDate() instead of getRange()
  3. Catch RuntimeException from getRange and substitute a zero-width range
  4. Pre-validate: reject vals matching 'P0Y'

Example fix

// before
Pair<Calendar,Calendar> range = timex.getRange(documentTime);
// after
if (timex.val().matches("P0+Y")) {
  Calendar now = documentTime.getDate();
  Pair<Calendar,Calendar> range = new Pair<>(now, now);
} else {
  Pair<Calendar,Calendar> range = timex.getRange(documentTime);
}
Defensive patterns

Strategy: validation

Validate before calling

if (timex.val() != null && timex.val().matches("P0+Y")) { handleAsPoint(); }

Try / catch

try { range = timex.getRange(docTime); } catch (RuntimeException e) { range = new Pair<>(docTime.getDate(), docTime.getDate()); }

Prevention

When it happens

Trigger: Calling getRange(documentTime) on a Timex whose val matches P\\d+Y with the digit part being 0 (e.g. 'P0Y').

Common situations: TimeML corpora containing degenerate durations like P0Y, often from upstream annotation or normalizer bugs that emitted a zero-length duration.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/74d48b1fc5ae08c4. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/time/Timex.java:467

      int yearRange = Integer.parseInt(this.val.substring(1, this.val.length() - 1));

      // in the future
      if (this.beginPoint < this.endPoint) {
        Calendar start = copyCalendar(rc);
        Calendar end = copyCalendar(rc);
        end.add(Calendar.YEAR, yearRange);
        return new Pair<>(start, end);
      }

      // in the past
      else if (this.beginPoint > this.endPoint) {
        Calendar start = copyCalendar(rc);
        Calendar end = copyCalendar(rc);
        start.add(Calendar.YEAR, 0 - yearRange);
        return new Pair<>(start, end);
      }

      throw new RuntimeException("begin and end are equal " + this);
    }
    // PDDM
    if (Pattern.matches("P\\d+M", this.val) && documentTime != null) {
      Calendar rc = documentTime.getDate();
      int monthRange = Integer.parseInt(this.val.substring(1, this.val.length() - 1));

      // in the future
      if (this.beginPoint < this.endPoint) {
        Calendar start = copyCalendar(rc);
        Calendar end = copyCalendar(rc);
        end.add(Calendar.MONTH, monthRange);
        return new Pair<>(start, end);
      }

      // in the past
      if (this.beginPoint > this.endPoint) {
        Calendar start = copyCalendar(rc);
        Calendar end = copyCalendar(rc);

View on GitHub (pinned to 1b7edd19c4)