{"record":{"id":"cb4397f7d81eb411","repo":"stanfordnlp/CoreNLP","slug":"must-capture-one-of-stderr-or-stdout","errorCode":null,"errorMessage":"Must capture one of stderr or stdout","messagePattern":"Must capture one of stderr or stdout","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/logging/RedwoodConfiguration.java","lineNumber":85,"sourceCode":"  public RedwoodConfiguration capture(final OutputStream stream) {\n    // Capture the stream\n    if (stream == System.out) {\n      tasks.add(() -> Redwood.captureSystemStreams(true, Redwood.realSysErr == System.err));\n    } else if (stream == System.err) {\n      tasks.add(() -> Redwood.captureSystemStreams(Redwood.realSysOut == System.out, true));\n    } else {\n      throw new IllegalArgumentException(\"Must capture one of stderr or stdout\");\n    }\n    return this;\n  }\n\n  public RedwoodConfiguration restore(final OutputStream stream) {\n    if (stream == System.out) {\n      tasks.add(() -> Redwood.captureSystemStreams(false, Redwood.realSysErr == System.err));\n    } else if (stream == System.err) {\n      tasks.add(() -> Redwood.captureSystemStreams(Redwood.realSysOut == System.out, false));\n    } else {\n      throw new IllegalArgumentException(\"Must capture one of stderr or stdout\");\n    }\n    return this;\n  }\n\n\n\n  public RedwoodConfiguration listenOnChannels(Consumer<Redwood.Record> listener, Object... channels) {\n    return this.handlers(\n        Handlers.chain(new FilterHandler(Collections.singletonList(new LogFilter() {\n              Set<Object> matchAgainst = new HashSet<>(Arrays.asList(channels));\n              @Override\n              public boolean matches(Redwood.Record message) {\n                for (Object channel : message.channels()) {\n                  if (matchAgainst.contains(channel)) {\n                    return true;\n                  }\n                }\n                return false;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/logging/RedwoodConfiguration.java#L67-L103","documentation":"RedwoodConfiguration.restore(OutputStream) throws IllegalArgumentException when the passed stream is neither System.out nor System.err. restore() exists solely to undo Redwood's capture of the standard system streams, so only those two streams are meaningful arguments.","triggerScenarios":"Calling restore(stream) with any other OutputStream: a FileOutputStream, ByteArrayOutputStream, a wrapped System.out (System.setOut(new PrintStream(...)) replaced the original so the reference no longer equals System.out), or null.","commonSituations":"Trying to restore a redirected stdout after System.setOut() was called (the field no longer aliases the original stream); passing a log file stream expecting restore to detach it; copying code and substituting a custom stream.","solutions":["Pass exactly System.out or System.err — the same object references Redwood captured","Restore before calling System.setOut()/setErr() so the identity checks still match","Use RedwoodConfiguration.None() or Redwood.stop() to disable Redwood entirely instead of restore()","To detach a custom stream, just stop using it / close it; restore() only applies to the system streams"],"exampleFix":"// before\nPrintStream mine = new PrintStream(new FileOutputStream(\"log.txt\"));\nconfig.restore(mine); // throws\n// after\nconfig.restore(System.out); // or System.err — must be the real system stream","handlingStrategy":"type-guard","validationCode":"if (stream != System.out && stream != System.err) {\n  throw new IllegalArgumentException(\"restore() accepts only System.out or System.err\");\n}\nconfig.restore(stream);","typeGuard":"static boolean isSystemStream(OutputStream s) {\n  return s == System.out || s == System.err;\n}","tryCatchPattern":"try {\n  config.restore(System.out);\n} catch (IllegalArgumentException e) {\n  log.warn(\"restore() needs System.out or System.err: {}\", e.getMessage());\n}","preventionTips":["Only pass System.out or System.err object references to restore()","Call restore() before any System.setOut()/setErr() redirection replaces the stream identity","Use RedwoodConfiguration.None() or Redwood.stop() for full shutdown instead of restore()","Remember restore() undoes capture of system streams, not arbitrary streams"],"tags":["logging","redwood","invalid-argument","stdout"],"backgroundTag":"invalid-argument-value","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"}