apache/seatunnel · error · IllegalArgumentException

Null InputStream

Error message

Null InputStream

What it means

The SFTPInputStream constructor validates its arguments and throws IllegalArgumentException when the wrapped InputStream is null. This guards against constructing a stream object that would fail later on first read, surfacing the mistake at creation time instead.

Solutions

  1. Check the code path that produced the null InputStream — re-open the remote file and verify get() succeeded.
  2. Verify the remote file exists and is readable before opening the stream (getFileStatus).
  3. If using the constructor directly, never pass an unchecked get() result; handle failure before construction.
  4. Retry the open; if it persists, check SFTP server logs for the failed open.

Example fix

// before
InputStream in = channel.get(path); // may be null on failure
SFTPInputStream s = new SFTPInputStream(in, channel, pool, stats);
// after
InputStream in = channel.get(path);
if (in == null) { throw new IOException("SFTP get returned null for " + path); }
SFTPInputStream s = new SFTPInputStream(in, channel, pool, stats);
Defensive patterns

Strategy: validation

Validate before calling

InputStream in = channel.get(path);
if (in == null) { throw new IOException("SFTP get failed (null stream) for " + path); }

Type guard

if (stream != null) { new SFTPInputStream(stream, channel, pool, stats); }

Try / catch

try { in = SFTPInputStream.getInstance(path, ...); }
catch (IllegalArgumentException e) { /* null stream: re-open with verified file */ }

Prevention

When it happens

Trigger: Calling SFTPInputStream.getInstance(...) or the constructor when the SFTP get/open call returned null instead of a stream — e.g. the remote open silently failed or a caller passed a null stream.

Common situations: SFTP server returning a null stream on get due to an unreported error; programmatic misuse of the constructor with a failed get() result not checked for null.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/b0cfbc4755053001. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-connectors-v2/connector-file/connector-file-sftp/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/sftp/system/SFTPInputStream.java:51

    public static final String E_NULL_INPUT_STREAM = "Null InputStream";
    public static final String E_STREAM_CLOSED = "Stream closed";
    public static final String E_CLIENT_NOT_CONNECTED = "Client not connected";

    private InputStream wrappedStream;
    private ChannelSftp channel;
    private SFTPConnectionPool connectionPool;
    private FileSystem.Statistics stats;
    private boolean closed;
    private long pos;

    SFTPInputStream(
            InputStream stream,
            ChannelSftp channel,
            SFTPConnectionPool connectionPool,
            FileSystem.Statistics stats) {

        if (stream == null) {
            throw new IllegalArgumentException(E_NULL_INPUT_STREAM);
        }
        if (channel == null || !channel.isConnected()) {
            throw new IllegalArgumentException(E_CLIENT_NULL);
        }
        this.wrappedStream = stream;
        this.channel = channel;
        this.connectionPool = connectionPool;
        this.stats = stats;

        this.pos = 0;
        this.closed = false;
    }

    @Override
    public void seek(long position) throws IOException {
        throw new IOException(E_SEEK_NOT_SUPPORTED);
    }

View on GitHub (pinned to cf67b549a7)