stanfordnlp/CoreNLP · error · IllegalStateException

Should not reach this switch case

Error message

Should not reach this switch case

What it means

SLF4JHandler.print() switches over a per-target Redwood flag (FORCE/STDOUT/STDERR/etc.) paired with an SLF4J logger. FORCE is an internal marker that should never reach this switch; hitting it means the handler's internal state is corrupted or was constructed inconsistently.

Solutions

  1. Report/inspect how SLF4JHandler's loggerAndLevel pairs were constructed; ensure no custom code sets the FORCE flag as a target level.
  2. Use an unmodified SLF4JHandler from a matching library version (stale patched jar is a common cause).
  3. Work around by using Handlers.output or stderr instead of SLF4JHandler while investigating.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  config.handlers(Handlers.slf4j).apply();
} catch (IllegalStateException e) {
  if (e.getMessage().contains("Should not reach this switch case")) {
    log.error("SLF4JHandler internal invariant broken; cause:", e);
    RedwoodConfiguration.empty().handlers(Handlers.stderr).apply();
  } else throw e;
}

Prevention

When it happens

Trigger: Internal: a record routed to an SLF4JHandler whose loggerAndLevel.second is the FORCE flag — only possible if handler construction/pairing logic changed or a custom subclass injected bad state.

Common situations: Practically never seen by library users; appears if SLF4JHandler internals are patched, deserialized incorrectly, or a custom LogRecordHandler feeds targets into it incorrectly.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/util/logging/SLF4JHandler.java:91

    }

    // Route the signal
    switch (loggerAndLevel.second) {
      case ERROR:
        loggerAndLevel.first.error(line);
        break;
      case WARN:
        loggerAndLevel.first.warn(line);
        break;
      case DEBUG:
        loggerAndLevel.first.debug(line);
        break;
      case STDOUT:
      case STDERR:
        loggerAndLevel.first.info(line);
        break;
      case FORCE:
        throw new IllegalStateException("Should not reach this switch case");
      default:
        throw new IllegalStateException("Unknown Redwood flag for slf4j integration: " + loggerAndLevel.second);
    }
  }

}

View on GitHub (pinned to 1b7edd19c4)