Skip to content

jline ConsoleReader discards the read line and returns null when the line reaches EOF #10

@chaoyu-tang

Description

@chaoyu-tang

In jline2 (jline-2.1.2.jar), the ConsoleReader discards the line content which has been read and returns null when the line reaches the end of the stream. See snippet of code in
class jline.console.ConsoleReader.java method:

public String readLine(String prompt, final Character mask) throws IOException:

            int c = pushBackChar.isEmpty() ? readCharacter() : pushBackChar.pop ();
            if (c == -1) {
                return null;
            }

and readCharacter():

public final int readCharacter() throws IOException {
    int c = reader.read();
    if (c >= 0) {
        Log.trace("Keystroke: ", c);
        // clear any echo characters
        if (terminal.isSupported()) {
            clearEcho(c);
        }
    }
    return c;
}

When EOF is reached in this line, the getCharacter() returns -1 and readLine returns null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions