stanfordnlp/CoreNLP · error · UnsupportedOperationException

PREV_IMMEDIATE not implemented for arg1=

Error message

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

What it means

TemporalOp.PREV_IMMEDIATE ('this past Friday') resolves arg2 to the immediately preceding instance relative to arg1, which must be a Time. A non-Time arg1 has no implemented semantics, so UnsupportedOperationException is thrown naming both argument classes.

Solutions

  1. Convert or resolve arg1 to a SUTime.Time before applying the operator
  2. Use the class names in the message to locate and fix the offending rule/call site
  3. Guard with instanceof Time and provide an explicit alternative path
  4. Upgrade or file an issue with CoreNLP if triggered by a built-in rule

Example fix

// before
TemporalOp.PREV_IMMEDIATE.apply(arg1, arg2, flags);
// after
if (!(arg1 instanceof Time)) { arg1 = arg1.getRange().end(); }
TemporalOp.PREV_IMMEDIATE.apply(arg1, arg2, flags);
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

try { result = TemporalOp.PREV_IMMEDIATE.apply(arg1, arg2, flags); } catch (UnsupportedOperationException e) { /* convert arg1 via getRange().end() and retry */ }

Prevention

When it happens

Trigger: Calling SUTime.TemporalOp.PREV_IMMEDIATE.apply(arg1, arg2, flags) where arg1 is a Duration/Range rather than a Time, usually from custom temporal rules.

Common situations: Parsing 'this past week' phrases where the reference date was mis-parsed; incorrect argument ordering in code that drives TemporalOp directly.

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/e7ae2d49b45953f6. Report an issue: GitHub.

Appendix: source

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

        // if (arg1 == null || arg2Prev == null) { return arg2Prev; }
        if (arg1 instanceof Time) {
          Time t = (Time) arg1;
          if (arg2 instanceof Duration) {
            return ((Duration) arg2).toTime(t, flags | RESOLVE_TO_PAST);
          } else {
            // TODO: flags?
            Temporal resolvedThis = arg2.resolve(t, RESOLVE_TO_PAST);
            if (resolvedThis != null) {
              if (resolvedThis instanceof Time) {
                if (((Time) resolvedThis).compareTo(t) >= 0) {
                  return PREV.apply(arg1, arg2);
                }
              }
            }
            return resolvedThis;
          }
        } else {
          throw new UnsupportedOperationException("PREV_IMMEDIATE not implemented for arg1=" + arg1.getClass() + ", arg2=" + arg2.getClass());
        }
      }
    },
    UNION {
      @Override
      public Temporal apply(Temporal arg1, Temporal arg2, int flags) {
        if (arg1 == null) {
          return arg2;
        }
        if (arg2 == null) {
          return arg1;
        }
        // return arg1.union(arg2);
        throw new UnsupportedOperationException("UNION not implemented for arg1=" + arg1.getClass() + ", arg2=" + arg2.getClass());
      }
    },
    INTERSECT {
      @Override

View on GitHub (pinned to 1b7edd19c4)