Ticket #16547: ReaquiringConsoleHandler.patch

File ReaquiringConsoleHandler.patch, 2.2 KB (added by floscher, 7 years ago)

Avoid closing System.err stream in ReaquiringConsoleHandler. Logging messages of warning level or higher levels were prevented from displaying since r14052.

  • core/src/org/openstreetmap/josm/tools/Logging.java

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    6161        private final Supplier<OutputStream> outputStreamSupplier;
    6262        private final Handler prioritizedHandler;
    6363        private OutputStream outputStreamMemo;
     64        /**
     65         * This variables is set to true as soon as the superconstructor has completed.
     66         * The superconstructor calls {@code setOutputStream(System.err)}, any subsequent call of
     67         * {@link #setOutputStream(OutputStream)} would then flush and close {@link System#err}. To avoid this,
     68         * we override {@link #setOutputStream(OutputStream)} to completely ignore all calls from the superconstructor.
     69         */
     70        private boolean superCompleted = false;
    6471
    6572        /**
    6673        * Construct a new {@link ReacquiringConsoleHandler}.
     
    7582            final Supplier<OutputStream> outputStreamSupplier,
    7683            final Handler prioritizedHandler
    7784        ) {
     85            super();
     86            superCompleted = true;
    7887            this.outputStreamSupplier = outputStreamSupplier;
    7988            this.prioritizedHandler = prioritizedHandler;
    8089
     
    97106
    98107        @Override
    99108        public synchronized void setOutputStream(final OutputStream outputStream) {
    100             // this wouldn't be necessary if StreamHandler made it possible to see what the current
    101             // output stream is set to
    102             this.outputStreamMemo = outputStream;
    103             super.setOutputStream(outputStream);
     109            // Ignore calls from superconstructor (see javadoc of the variable for details)
     110            if (superCompleted) {
     111                // this wouldn't be necessary if StreamHandler made it possible to see what the current
     112                // output stream is set to
     113                this.outputStreamMemo = outputStream;
     114                super.setOutputStream(outputStream);
     115            }
    104116        }
    105117
    106118        @Override