stanfordnlp/CoreNLP · error · UnsupportedOperationException

PREV not implemented for arg1=

Error message

PREV not implemented for arg1=${arg1.getClass()}, arg2=${arg2.getClass()}

What it means

TemporalOp.PREV ('last week', 'previous Monday') resolves arg2 backwards using arg1 as a Time reference. If arg1 is not a Time, the backward resolution is undefined and the operator throws UnsupportedOperationException stating the two argument classes.

Solutions

  1. Pass a SUTime.Time as arg1 — resolve the reference temporal to a Time first
  2. Read the exception message's class names and fix the rule or call site that produced them
  3. Add an instanceof Time guard with an explicit fallback
  4. Report a CoreNLP bug if a shipped rule hits this

Example fix

// before
TemporalOp.PREV.apply(arg1, arg2, 0);
// after
if (arg1 instanceof Time) {
  TemporalOp.PREV.apply(arg1, arg2, 0);
} else {
  TemporalOp.PREV.apply(arg1.getRange().begin(), arg2, 0);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(arg1 instanceof SUTime.Time)) { throw new IllegalArgumentException("PREV requires arg1 to be a Time"); }

Type guard

boolean canApplyPrev(SUTime.Temporal arg1) { return arg1 instanceof SUTime.Time; }

Try / catch

try { result = TemporalOp.PREV.apply(arg1, arg2, flags); } catch (UnsupportedOperationException e) { /* resolve arg1 to a Time and retry */ }

Prevention

When it happens

Trigger: Calling SUTime.TemporalOp.PREV.apply(arg1, arg2, flags) with arg1 being a Duration, Range, or other non-Time Temporal, typically from custom TokensRegex temporal rules.

Common situations: Parsing 'last year'/'previous month' style phrases where the anchoring time expression was not recognized; programmatic misuse of the TemporalOp API.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/time/SUTime.java:1090

      }
    },
    // (predecessor) Previous week/day/...
    PREV {
      @Override
      public Temporal apply(Temporal arg1, Temporal arg2, int flags) {
        if (arg2 == null) {
          return arg1;
        }
        Temporal arg2Prev = arg2.prev();
        if (arg1 == null || arg2Prev == null) {
          return arg2Prev;
        }
        if (arg1 instanceof Time) {
          // TODO: flags?
          Temporal resolved = arg2Prev.resolve((Time) arg1, 0 /*RESOLVE_TO_PAST */);
          return resolved;
        } else {
          throw new UnsupportedOperationException("PREV not implemented for arg1=" + arg1.getClass() + ", arg2=" + arg2.getClass());
        }
      }
    },
    // This past week/friday
    PREV_IMMEDIATE {
      @Override
      public Temporal apply(Temporal arg1, Temporal arg2, int flags) {
        if (arg1 == null) {
          return new RelativeTime(PREV_IMMEDIATE, arg2);
        }
        if (arg2 == null) {
          return arg1;
        }
        // Temporal arg2Prev = arg2.prev();
        // if (arg1 == null || arg2Prev == null) { return arg2Prev; }
        if (arg1 instanceof Time) {
          Time t = (Time) arg1;
          if (arg2 instanceof Duration) {

View on GitHub (pinned to 1b7edd19c4)