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

Jline completion has logic issues with terminal and prompt widths (StringIndexOutOfBoundsException) #604

Closed
bdw429s opened this issue Nov 18, 2020 · 9 comments
Labels
Milestone

Comments

@bdw429s
Copy link
Contributor

bdw429s commented Nov 18, 2020

After updating CommandBox CLI to JLine 3.17.1, some users receive this error when hitting tab:

java.lang.StringIndexOutOfBoundsException: String index out of range: -29
	at java.base/java.lang.String.substring(String.java:1837)
	at org.jline.reader.impl.LineReaderImpl.candidateStartPosition(LineReaderImpl.java:5192)
	at org.jline.reader.impl.LineReaderImpl.doList(LineReaderImpl.java:5048)
	at org.jline.reader.impl.LineReaderImpl.doList(LineReaderImpl.java:4998)
	at org.jline.reader.impl.LineReaderImpl.doComplete(LineReaderImpl.java:4595)
	at org.jline.reader.impl.LineReaderImpl.doComplete(LineReaderImpl.java:4365)
	at org.jline.reader.impl.LineReaderImpl.expandOrComplete(LineReaderImpl.java:4304)
	at org.jline.reader.impl.LineReaderImpl$1.apply(LineReaderImpl.java:3798)
	at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:670)
	at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:459)

After a lot of debugging, I have determined that the error happens when the prompt is wider than the terminal width.

There are two incorrect assumptions Jline is making. The first is that the prompt will never be wider than the terminal width. There is a popular module for CommandBox called Bullet Train that gives nice, pretty prompt like this, which can also be long depending on how much information is displayed:

image

The second incorrect assumption JLine is making is that there will not be any line breaks in the prompt itself. you can see in the above image that the ACTUAL prompt is just the > character on the second line. In fact, depending on your terminal size, there can be more than one line break in the prompt string.

image

Jline needs to calculate the prompt length after the last line break and put in a check to ensure it is never a negative number.

@bdw429s
Copy link
Contributor Author

bdw429s commented Nov 18, 2020

@gnodet Let me know if there's anything I can do to help get the fix out for this. I'd love to be able to squash this regression in my next release.

@mattirn
Copy link
Collaborator

mattirn commented Nov 18, 2020

Actually this has been already fixed in commit a5686ab in case you have not enabled JLine option AUTO_MENU_LIST (#582).

Now the problem is present only when option AUTO_MENU_LIST has been enabled (3.17.2-SNAPSHOT).

@bdw429s
Copy link
Contributor Author

bdw429s commented Nov 18, 2020

@mattirn Thank you for the update. Any idea when the fix will be available in a stable release?

@mattirn
Copy link
Collaborator

mattirn commented Nov 18, 2020

@bdw429s When you were planning to do your next release? Maybe we can synchronize our releases... I have not any plan for new features.

@bdw429s
Copy link
Contributor Author

bdw429s commented Nov 18, 2020

@mattirn Depending on how many users this is affecting, I may put out a patch release as soon as this fix is available.

@mattirn mattirn added the bug label Nov 19, 2020
@mattirn mattirn added this to the 3.17.2 milestone Nov 19, 2020
@bdw429s
Copy link
Contributor Author

bdw429s commented Dec 4, 2020

@mattirn Hi, is there an ETA on the 3.17.2 milestone so I can plan my release? Or perhaps a snapshot build I can use in the meantime?

@mattirn
Copy link
Collaborator

mattirn commented Dec 4, 2020

@bdw429s I'm on 'maintenance mode' for me 3.17.2 can be released also next week. I still would like to look if I can found a better solution for #609.
Snapshot build you can download from jline/3.17.2-SNAPSHOT. Would be great if you can test with it before 3.17.2 will be released.

@bdw429s
Copy link
Contributor Author

bdw429s commented Dec 4, 2020

Thanks @mattirn I've pointed my build at the sonatype repo to grab 3.17.2-SNAPSHOT and I'll give it a test.

@bdw429s
Copy link
Contributor Author

bdw429s commented Dec 4, 2020

@mattirn After a quick test on 3.17.2-SNAPSHOT, the original error does seem to be gone and it looks good.

I also activated the AUTO_MENU_LIST option as a test and it looks very cool. I was able to get a divide by zero error once as it was completing but I didn't have full stack traces enabled. After I enabled more debugging I couldn't get the divide by zero error again to save my life. I'll keep my eye out for that one.

@mattirn mattirn mentioned this issue Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants