stanfordnlp/CoreNLP · error · IllegalStateException
Cannot modify Redwood when within a track
Error message
Cannot modify Redwood when within a track
What it means
Redwood.RecordHandlerTree.addChild(handler) throws IllegalStateException when Redwood.depth != 0, i.e. when a logging track is currently open. The handler tree — the configuration of which log handlers are active — may only be modified at track depth 0, because mutating it mid-track would corrupt the active track stack.
Solutions
- Move all Redwood.addChild/output/apply configuration calls to program startup, before any startTrack()
- Defer configuration until after the tracked region ends (Redwood.depth == 0)
- If dynamic handler changes are needed, end and restart the track around the reconfiguration
- Assert Redwood.depth == 0 (or catch IllegalStateException) in helper code that configures logging
Example fix
// before
Redwood.startTrack("run");
Redwood.show(Redwood.ERR); // reconfigures handlers -> throws
// after
Redwood.show(Redwood.ERR);
Redwood.startTrack("run");
// ... work ...
Redwood.endTrack("run"); Defensive patterns
Strategy: validation
Validate before calling
if (Redwood.depth != 0) {
throw new IllegalStateException("Configure Redwood handlers only outside tracks");
}
Redwood.addChild(handler); Try / catch
try {
Redwood.addChild(handler);
} catch (IllegalStateException e) {
log.warn("Deferred handler add: {}", e.getMessage());
pendingHandlers.add(handler); // apply after endTrack
} Prevention
- Configure all handlers at startup, before any startTrack()
- Never call RedwoodConfiguration.apply/output/stdout/stderr inside logged regions
- Queue desired handler changes and apply them at depth 0
- Add assertions in shared utility code that wraps Redwood configuration
When it happens
Trigger: Calling Redwood.addChild(handler) (or convenience setters Redwood.output/stdout/stderr/slf4j/javaUtil/apply that delegate to it) between startTrack() and endTrack(), e.g. inside a logged region of code.
Common situations: Library code that reconfigures logging inside a tracked training loop; user code calling RedwoodConfiguration.apply(...) inside a track; handlers added per-request while a top-level track is open.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- OutputHandler received endTrack() without matching…
- Called remove() before any elements returned
- Cannot nest Redwood threaded environments
- Could not find Redwood log property:
- Must capture one of stderr or stdout
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d0df28a817d5bf5c.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/logging/Redwood.java:649
head = null;
}
public RecordHandlerTree(LogRecordHandler head) {
this.isRoot = false;
this.head = head;
}
// -- Core Tree Methods --
public LogRecordHandler head(){
return head;
}
public Iterator<RecordHandlerTree> children(){
return children.iterator();
}
// -- Utility Methods --
public void addChild(LogRecordHandler handler){
if(Redwood.depth != 0){
throw new IllegalStateException("Cannot modify Redwood when within a track");
}
children.add(new RecordHandlerTree(handler));
}
protected void addChildTree(RecordHandlerTree tree){
if(Redwood.depth != 0){
throw new IllegalStateException("Cannot modify Redwood when within a track");
}
children.add(tree);
}
public LogRecordHandler removeChild(LogRecordHandler handler){
if(Redwood.depth != 0){
throw new IllegalStateException("Cannot modify Redwood when within a track");
}
Iterator<RecordHandlerTree> iter = children();
while(iter.hasNext()){
LogRecordHandler cand = iter.next().head();
if(cand == handler){
iter.remove();View on GitHub (pinned to 1b7edd19c4)