Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac Iterm2 Paste slowly causes Jline to throw ClosedException #757

Closed
tli-ocient opened this issue Dec 6, 2021 · 3 comments
Closed

Mac Iterm2 Paste slowly causes Jline to throw ClosedException #757

tli-ocient opened this issue Dec 6, 2021 · 3 comments

Comments

@tli-ocient
Copy link

tli-ocient commented Dec 6, 2021

I have a simple command line interface which reads in a loop via JLine. I have found that launching this program in ITerm2 and then using the Iterm2 "Paste slowly" command causes a ClosedException to be thrown by Jline. I have also been able to reproduce this (though not as consistently) by CMD + V with a very long string into the command line interface.

Setup

  • java 13.0.1 2019-10-15
  • 3.21.1-SNAPSHOT
  • Ubuntu 16.04.7 LTS
  • MacOs Monterey
    Note in the above setup, my java program is running on a container with Ubuntu and I am SSHed in from my Macbook in Iterm2.

Details

My CLI program is very simple. It just calls the standard readLine function. in a loop until it finds a semicolon ;. After that,
it does things with the input.

How to reproduce

  1. Launch CLI program
  2. In Iterm2 go Edit > Paste Special > Paste Slowly (Any String will do)

Alternative way to reproduce

  1. Launch CLI program
  2. Command + V (Paste) with a very long string.

What I see

org.jline.reader.EndOfFileException: org.jline.utils.ClosedException
	at org.jline.keymap.BindingReader.readStringUntil(BindingReader.java:141)
	at org.jline.reader.impl.LineReaderImpl.doReadStringUntil(LineReaderImpl.java:931)
	at org.jline.reader.impl.LineReaderImpl.beginPaste(LineReaderImpl.java:5743)
	at org.jline.reader.impl.LineReaderImpl$1.apply(LineReaderImpl.java:3778)
	at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:679)
	at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:468)
        [...my CLI code...]
Caused by: org.jline.utils.ClosedException
	at org.jline.keymap.BindingReader.readStringUntil(BindingReader.java:136)
	... 6 more

I've also attached JDB and put a breakpoint at org.jline.keymap.BindingReader:136.
I've printed out some relevant variables.

Breakpoint hit:
Breakpoint hit: "thread=main", org.jline.keymap.BindingReader.readStringUntil(), line=136 bci=115

main[1] print sequence
 sequence = ""
main[1] print buf
 buf = instance of char[64] (id=1343)
main[1] print idx
 idx = -1
main[1] print l
 l = -1

It appears that sequence it is looking for is an empty string. I can reproduce this quite easily if you need more information. I took a crack at fixing this here: #756
This passes all of your unit tests and fixes my problem. I don't know the context of this code very well so perhaps this is not the proper fix. It doesn't seem like it would ever find an empty string here and we should just return the whole string in this case.
Though, this is just my guess. Please let me know if you need more information.

@gnodet
Copy link
Member

gnodet commented May 19, 2022

There's something wrong in your analysis: the sequence variable should definitely not be an empty string and the only value actually passed to this method is BRACKETED_PASTE_END which equals to "\033[201~".

However, I've been able to reproduce the problem, so I'll have a look.

@gnodet
Copy link
Member

gnodet commented May 19, 2022

So the problem is that the readStringUntil method should be blocking, but if the input does not contain the end sequence immediately, it will throw a ClosedException. Returning an half-read string as in #756 will loose some data, so I'll provide a correct fix.

@gnodet
Copy link
Member

gnodet commented Jun 15, 2022

@tli-ocient could you verify that #782 actually works for you ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants