{"record":{"id":"2a180cdf39c6db54","repo":"stanfordnlp/CoreNLP","slug":"treebank-is-read-only","errorCode":null,"errorMessage":"Treebank is read-only","messagePattern":"Treebank is read-only","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/Treebank.java","lineNumber":507,"sourceCode":"        }\n      }\n      pw.println(\"    Cats: \" + Counters.toString(cats, nf));\n      pw.println(\"    Tags: \" + Counters.toString(tags, nf));\n      pw.println(\"    \" + starts.size() + \" start categories: \" + Counters.toString(starts, nf));\n      if ( ! puncts.isEmpty()) {\n        pw.println(\"    Puncts: \" + Counters.toString(puncts, nf));\n      }\n    }\n    return sw.toString();\n  }\n\n\n  /**\n   * This operation isn't supported for a Treebank.  Tell them immediately.\n   */\n  @Override\n  public boolean remove(Object o) {\n    throw new UnsupportedOperationException(\"Treebank is read-only\");\n  }\n\n}\n","sourceCodeStart":489,"sourceCodeEnd":511,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/Treebank.java#L489-L511","documentation":"Deliberate UnsupportedOperationException from Treebank.remove(Object): a Treebank is treated as a read-only collection view over parsed tree files, and mutation of the underlying corpus is not supported, so the single-element removal operation (and the other mutators it represents) fail fast rather than silently doing nothing or mutating state. It fires whenever client code attempts to remove a tree from a Treebank as if it were a mutable Collection.","triggerScenarios":"Calling treebank.remove(treeOrObject), or any bulk operation that relies on removal such as treebank.removeAll(...), retainAll(...), or Iterator.remove() backed by this collection.","commonSituations":"Trying to filter a loaded corpus by deleting trees; generic Collection-processing code that mutates its argument; removing items while iterating a Treebank.","solutions":["Build a new filtered collection instead of mutating: iterate and add survivors to a List or new MemoryTreebank.","If file-backed removal is needed, rewrite the corpus file without the unwanted trees.","Wrap the Treebank in a custom Collection implementing remove if mutation is truly required."],"exampleFix":"// before\ntreebank.remove(tree);\n// after\nList<Tree> kept = new ArrayList<>();\nfor (Tree t : treebank) if (keep(t)) kept.add(t);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { treebank.remove(tree); } catch (UnsupportedOperationException e) { /* filter into a new collection instead */ }","preventionTips":["Treat Treebank as read-only by design.","Filter into a new List or MemoryTreebank instead of removing.","Do not hand Treebank objects to mutation-based Collection APIs."],"tags":["collections","unsupported-operation","immutability"],"backgroundTag":"unsupported-operation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}