stanfordnlp/CoreNLP · error · OutOfMemoryError

Refusal to create such large arrays.

Error message

Refusal to create such large arrays.

What it means

ExhaustiveDependencyParser.parse allocates O(n^2)+ chart arrays; when the sentence is longer than the current arraySize, it refuses to grow arrays beyond the test maxLength (or its own myMaxLength) and throws OutOfMemoryError 'Refusal to create such large arrays.' This is a deliberate guard against absurd memory allocation for over-long sentences.

Solutions

  1. Split input into sentences within maxLength before parsing
  2. Raise op.testOptions.maxLength (and ensure -Xmx heap is large enough for the O(n^2) arrays)
  3. Increase the parser's length limit configuration so the guard permits the sentence length

Example fix

// before
parser.parse(longDocumentText); // length > maxLength
// after
for (List<TaggedWord> sent : sentenceSplit(tokenize(longDocumentText))) {
  if (sent.size() <= op.testOptions.maxLength) parser.parse(sent);
}
Defensive patterns

Strategy: validation

Validate before calling

if (sentence.size() > op.testOptions.maxLength) throw new IllegalArgumentException("Sentence length " + sentence.size() + " exceeds maxLength " + op.testOptions.maxLength);

Type guard

boolean parseable(List<TaggedWord> s, Options op) { return s.size() <= op.testOptions.maxLength; }

Try / catch

try { parser.parse(sentence); } catch (OutOfMemoryError e) { if (e.getMessage().contains("Refusal to create such large arrays")) { splitAndReparse(sentence); } }

Prevention

When it happens

Trigger: Calling parse(something) with a sentence whose length exceeds op.testOptions.maxLength + 1 or the parser's myMaxLength, triggering the pre-allocation guard before createArrays is attempted.

Common situations: Feeding whole documents/paragraphs as one 'sentence' instead of sentence-splitting first; maxLength option set lower than the actual test data; tokenization producing unexpectedly long inputs.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/parser/lexparser/ExhaustiveDependencyParser.java:179

  public boolean oPossible(Hook hook) {
    return (hook.isPreHook() ? oPossibleByR[hook.end][hook.head][dg.tagBin(hook.tag)] : oPossibleByL[hook.start][hook.head][dg.tagBin(hook.tag)]);
  }

  @Override
  public boolean iPossible(Hook hook) {
    return (hook.isPreHook() ? iPossibleByR[hook.start][hook.head][dg.tagBin(hook.tag)] : iPossibleByL[hook.end][hook.head][dg.tagBin(hook.tag)]);
  }

  @Override
  public boolean parse(List<? extends HasWord> sentence) {
    if (op.testOptions.verbose) {
      Timing.tick("Starting dependency parse.");
    }
    this.sentence = sentence;
    int length = sentence.size();
    if (length > arraySize) {
      if (length > op.testOptions.maxLength + 1 || length >= myMaxLength) {
        throw new OutOfMemoryError("Refusal to create such large arrays.");
      } else {
        try {
          createArrays(length + 1);
        } catch (OutOfMemoryError e) {
          myMaxLength = length;
          if (arraySize > 0) {
            try {
              createArrays(arraySize);
            } catch (OutOfMemoryError e2) {
              throw new RuntimeException("CANNOT EVEN CREATE ARRAYS OF ORIGINAL SIZE!!! " + arraySize);
            }
          }
          throw e;
        }
        arraySize = length + 1;
        if (op.testOptions.verbose) {
          log.info("Created dparser arrays of size " + arraySize);
        }

View on GitHub (pinned to 1b7edd19c4)