stanfordnlp/CoreNLP · error · IllegalArgumentException

Could not find Language or predefined relative pronouns…

Error message

Could not find Language or predefined relative pronouns pattern in the request

What it means

The second guard in ProcessUniversalEnhancerRequest.getRelativePronouns: if the request has no Language set (and no predefined relative-pronouns pattern supplied), the method throws IllegalArgumentException("Could not find Language or predefined relative pronouns pattern in the request"). It fires after the language-switch when the request lacks both pieces of information.

Solutions

  1. Call setLanguage(...) on the request before processing
  2. Supply a predefined relative-pronouns pattern in the request when language detection is unavailable
  3. Validate the request (language or pattern present) before invoking the enhancer
  4. Catch IllegalArgumentException and return a clear request-validation error to the caller

Example fix

// before
ProcessUniversalEnhancerRequest request = new ProcessUniversalEnhancerRequest();
enhancer.process(request); // no language
// after
ProcessUniversalEnhancerRequest request = new ProcessUniversalEnhancerRequest();
request.setLanguage(Language.English);
enhancer.process(request);
Defensive patterns

Strategy: validation

Validate before calling

if (request.getLanguage() == null && request.getRelativePronounsPattern() == null) {
  throw new IllegalArgumentException("Request must set language or a relative pronouns pattern");
}

Try / catch

try { enhancer.process(request); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Could not find Language")) { throw new RequestValidationException("language/pattern missing", e); } throw e; }

Prevention

When it happens

Trigger: Sending a ProcessUniversalEnhancerRequest with no language field populated and no predefined relative-pronouns pattern, then invoking relativePronounsPattern/getRelativePronouns during enhancement.

Common situations: Building the request programmatically and forgetting setLanguage; deserializing a request where the language field was dropped; calling the enhancer pipeline directly without a fully populated request object.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/trees/ud/ProcessUniversalEnhancerRequest.java:87

   */
  public static Pattern getRelativePronouns(CoreNLPProtos.DependencyEnhancerRequest request) {
    if (request.hasRelativePronouns()) {
      return Pattern.compile(request.getRelativePronouns());
    }
    if (request.hasLanguage()) {
      switch(request.getLanguage()) {
      case English:
      case UniversalEnglish:
        return EnglishPatterns.RELATIVIZING_WORD_PATTERN;
      case Chinese:
      case UniversalChinese:
        // there are no relative pronouns in Chinese!
        return null;
      default:
        throw new IllegalArgumentException("Relative word pattern not defined for " + request.getLanguage());
      }
    }
    throw new IllegalArgumentException("Could not find Language or predefined relative pronouns pattern in the request");
  }

  /**
   * Process a single request, adding enhanced dependencies to each sentence in the document
   */
  @Override
  public void processInputStream(InputStream in, OutputStream out) throws IOException {
    CoreNLPProtos.DependencyEnhancerRequest request = CoreNLPProtos.DependencyEnhancerRequest.parseFrom(in);

    Pattern relativePronounsPattern = getRelativePronouns(request);

    CoreNLPProtos.Document response = processRequest(relativePronounsPattern, request);
    response.writeTo(out);
  }

  /**
   * The inherited main program will either enhance a single document,
   * or will listen to stdin and enhance every document that comes in

View on GitHub (pinned to 1b7edd19c4)