{"record":{"id":"265c335fed4406c3","repo":"stanfordnlp/CoreNLP","slug":"cannot-even-create-arrays-of-original-size-265c33","errorCode":null,"errorMessage":"CANNOT EVEN CREATE ARRAYS OF ORIGINAL SIZE!!","messagePattern":"CANNOT EVEN CREATE ARRAYS OF ORIGINAL SIZE!!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/edu/stanford/nlp/parser/lexparser/ExhaustivePCFGParser.java","lineNumber":2197,"sourceCode":"      }\n    } catch (OutOfMemoryError oome) {\n      oome.printStackTrace();\n    }\n  }\n\n  private void considerCreatingArrays(int length) {\n    if (length > op.testOptions.maxLength + 1 || length >= myMaxLength) {\n      throw new OutOfMemoryError(\"Refusal to create such large arrays.\");\n    } else {\n      try {\n        createArrays(length + 1);\n      } catch (OutOfMemoryError e) {\n        myMaxLength = length;\n        if (arraySize > 0) {\n          try {\n            createArrays(arraySize);\n          } catch (OutOfMemoryError e2) {\n            throw new RuntimeException(\"CANNOT EVEN CREATE ARRAYS OF ORIGINAL SIZE!!\");\n          }\n        }\n        throw e;\n      }\n      arraySize = length + 1;\n      if (op.testOptions.verbose) {\n        log.info(\"Created PCFG parser arrays of size \" + arraySize);\n      }\n    }\n  }\n\n  protected void createArrays(int length) {\n    // zero out some stuff first in case we recently ran out of memory and are reallocating\n    clearArrays();\n\n    int numTags = tagIndex.size();\n    // allocate just the parts of iScore and oScore used (end > start, etc.)\n    // todo: with some modifications to doInsideScores, we wouldn't need to allocate iScore[i,length] for i != 0 and i != length","sourceCodeStart":2179,"sourceCodeEnd":2215,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/ExhaustivePCFGParser.java#L2179-L2215","documentation":"When createArrays for the requested sentence length fails with OutOfMemoryError, the parser attempts to restore its previous array size (arraySize). If even that fails, it throws this RuntimeException, meaning the heap is too small to recreate the parser's original chart arrays — internal state may be broken.","triggerScenarios":"A parse request triggers reallocation to a larger sentence length; allocation fails; the fallback createArrays(arraySize) also throws OutOfMemoryError due to insufficient heap.","commonSituations":"Running the parser with a small -Xmx heap and then feeding a long sentence that grows the chart; memory already consumed elsewhere; container memory limits.","solutions":["Increase JVM heap (e.g. -Xmx4g or more) so chart arrays can be allocated.","Lower op.testOptions.maxLength so the parser refuses earlier and never attempts the huge reallocation.","Avoid reusing the parser after this error; reload the parser in a larger-heap environment."],"exampleFix":"// before\njava -Xmx1g -cp stanford-parser.jar ... parser.parse(longSentence);\n// after\njava -Xmx8g -cp stanford-parser.jar ... op.testOptions.maxLength = 60;","handlingStrategy":"try-catch","validationCode":"// ensure generous heap before constructing long-sentence parses\nlong maxHeap = Runtime.getRuntime().maxMemory();\nif (maxHeap < 2L * 1024 * 1024 * 1024 && sentence.size() > 100) throw new IllegalStateException(\"insufficient heap for long parse\");","typeGuard":null,"tryCatchPattern":"try { pq.parse(sentence); } catch (RuntimeException e) { if (e.getMessage().contains(\"CANNOT EVEN CREATE ARRAYS\")) { reloadParserWithLargerHeap(); } else throw e; }","preventionTips":["Run the parser with a large -Xmx sized to maxLength (chart memory grows cubically).","Avoid reusing a parser instance after an OutOfMemoryError; reload it.","Enforce maxLength caps before parsing so the huge reallocation is never attempted."],"tags":["java","nlp","parsing","out-of-memory","heap"],"backgroundTag":"internal-invariant-violation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}