stanfordnlp/CoreNLP · error · UnsupportedOperationException

NEXT_IMMEDIATE not implemented for arg1=

Error message

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

What it means

TemporalOp.NEXT_IMMEDIATE ('this coming Friday' style) requires arg1 to be a Time used as the reference to resolve arg2 forward to the immediate next instance. If arg1 is any other Temporal subtype, the operator is unimplemented and throws UnsupportedOperationException listing both argument classes.

Solutions

  1. Pass a SUTime.Time as arg1 (resolve/convert the reference temporal to a Time first)
  2. Inspect the message's class names to find which rule produced the wrong argument types
  3. Use instanceof Time to guard before calling apply and choose a different operator otherwise
  4. File a CoreNLP issue if a built-in rule produces this combination

Example fix

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

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling SUTime.TemporalOp.NEXT_IMMEDIATE.apply(arg1, arg2, flags) with a non-Time arg1 (Duration, Range, or composite temporal), typically from a custom TokensRegex temporal rule.

Common situations: Parsing phrases like 'next Friday' or 'this coming week' where the anchoring reference time failed to parse as a Time; custom rules with swapped or malformed argument order.

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

Appendix: source

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

        // if (arg1 == null || arg2Next == null) { return arg2Next; }
        if (arg1 instanceof Time) {
          Time t = (Time) arg1;
          if (arg2 instanceof Duration) {
            return ((Duration) arg2).toTime(t, flags | RESOLVE_TO_FUTURE);
          } else {
            // TODO: flags?
            Temporal resolvedThis = arg2.resolve(t, RESOLVE_TO_FUTURE);
            if (resolvedThis != null) {
              if (resolvedThis instanceof Time) {
                if (((Time) resolvedThis).compareTo(t) <= 0) {
                  return NEXT.apply(arg1, arg2);
                }
              }
            }
            return resolvedThis;
          }
        } else {
          throw new UnsupportedOperationException("NEXT_IMMEDIATE not implemented for arg1=" + arg1.getClass() + ", arg2=" + arg2.getClass());
        }
      }
    },
    // Use arg1 as reference to resolve arg2 (take more general fields from arg1
    // and apply to arg2)
    THIS {
      @Override
      public Temporal apply(Temporal arg1, Temporal arg2, int flags) {
        if (arg1 == null) {
          return new RelativeTime(THIS, arg2, flags);
        }
        if (arg1 instanceof Time) {
          if (arg2 instanceof Duration) {
            return ((Duration) arg2).toTime((Time) arg1, flags);
          } else {
            // TODO: flags?
            return arg2.resolve((Time) arg1, flags | RESOLVE_TO_THIS);
          }

View on GitHub (pinned to 1b7edd19c4)