Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void raise(Signal signal) {
public void processInputByte(int c) throws IOException {
boolean flushOut = doProcessInputByte(c);
slaveInputPipe.flush();
if (flushOut) {
if (flushOut && masterOutput != null) {
masterOutput.flush();
}
}
Expand All @@ -291,7 +291,7 @@ public void processInputBytes(byte[] input, int offset, int length) throws IOExc
flushOut |= doProcessInputByte(input[offset + i]);
}
slaveInputPipe.flush();
if (flushOut) {
if (flushOut && masterOutput != null) {
masterOutput.flush();
}
}
Expand Down Expand Up @@ -350,6 +350,9 @@ protected boolean doProcessInputByte(int c) throws IOException {
* @throws IOException if anything wrong happens
*/
protected void processOutputByte(int c) throws IOException {
if (masterOutput == null) {
return;
}
if (attributes.getOutputFlag(OutputFlag.OPOST)) {
if (c == '\n') {
if (attributes.getOutputFlag(OutputFlag.ONLCR)) {
Expand Down Expand Up @@ -413,12 +416,16 @@ public void write(byte[] b, int off, int len) throws IOException {

@Override
public void flush() throws IOException {
masterOutput.flush();
if (masterOutput != null) {
masterOutput.flush();
}
}

@Override
public void close() throws IOException {
masterOutput.close();
if (masterOutput != null) {
masterOutput.close();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) the original author(s).
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* https://opensource.org/licenses/BSD-3-Clause
*/
package org.jline.terminal.impl;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

class NullOutputCloseTest {

@Test
void testCloseWithNullMasterOutput() throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
ExternalTerminal terminal = new ExternalTerminal("test", "dumb", in, null, StandardCharsets.UTF_8);
assertDoesNotThrow(terminal::close);
}
}