{"record":{"id":"165c25488fae8caa","repo":"stanfordnlp/CoreNLP","slug":"retainall-not-implemented","errorCode":null,"errorMessage":"retainAll not implemented","messagePattern":"retainAll not implemented","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/IntervalTree.java","lineNumber":197,"sourceCode":"      }\n      if (curIter != null && curIter.hasNext()) {\n        return curIter.next();\n      } else return null;\n    }\n  }\n\n  @Override\n  public boolean removeAll(Collection<?> c) {\n    boolean modified = false;\n    for (Object t:c) {\n      if (remove(t)) { modified = true; }\n    }\n    return modified;\n  }\n\n  @Override\n  public boolean retainAll(Collection<?> c) {\n    throw new UnsupportedOperationException(\"retainAll not implemented\");\n  }\n\n  @Override\n  public boolean contains(Object o) {\n    try {\n      return contains((T) o);\n    } catch (ClassCastException ex) {\n      return false;\n    }\n  }\n\n  @Override\n  public boolean remove(Object o) {\n    try {\n      return remove((T) o);\n    } catch (ClassCastException ex) {\n      return false;\n    }","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/IntervalTree.java#L179-L215","documentation":"Sentinel UnsupportedOperationException from IntervalTree.retainAll(Collection<?> c): the interval-tree-backed collection implements removeAll by delegating to per-element remove, but intersection-based retention (keeping only elements also in c) was never implemented, so the method throws instead of returning a wrong result. It fires whenever generic collection code calls retainAll on an IntervalTree.","triggerScenarios":"Calling retainAll(...) on any IntervalTree instance, e.g. when using it where a generic Collection is expected and the code invokes bulk retention.","commonSituations":"Passing an IntervalTree to library code that calls retainAll as part of set operations; assuming full java.util.Collection support.","solutions":["Implement retention yourself: iterate the tree, collect items not in c, and remove them via removeAll(Collection) or individual remove calls","Copy the contents into a HashSet and apply retainAll there if tree structure is not needed afterwards","Avoid APIs that require retainAll on IntervalTree"],"exampleFix":"// before\ntree.retainAll(keep); // throws\n// after\nList<T> toRemove = new ArrayList<>();\nfor (T t : tree) if (!keep.contains(t)) toRemove.add(t);\ntree.removeAll(toRemove);","handlingStrategy":"try-catch","validationCode":"if (collection instanceof edu.stanford.nlp.util.IntervalTree) { /* use manual retain loop instead of retainAll */ }","typeGuard":null,"tryCatchPattern":"try { tree.retainAll(c); } catch (UnsupportedOperationException e) { /* fall back to iterative removal */ }","preventionTips":["Avoid passing IntervalTree to code that performs generic Collection bulk ops","Filter into a standard Set when set semantics are needed","Check the class's unsupported operations before using it as a Collection"],"tags":["unsupported-operation","collection","interval-tree"],"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"}