jdillon / mvnsh

Maven Shell
Other
49 stars 18 forks source link

jline3 history files are not compatible with previous versions; causing exceptions on startup #24

Open mosabua opened 7 years ago

mosabua commented 7 years ago

Using mvnsh-assembly-1.2.0-20170425.065527-18-bin.zip I get this at startup:


$ mvnsh
Maven Shell (1.2.0-SNAPSHOT,201704250654)

Type 'help' for more information.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] Error reloading history file: /home/manfred/.m2/mvnsh.history
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(String.java:1967)
        at org.jline.reader.impl.history.DefaultHistory.lambda$load$0(DefaultHistory.java:80)
        at java.util.Iterator.forEachRemaining(Iterator.java:116)
        at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
        at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
        at org.jline.reader.impl.history.DefaultHistory.load(DefaultHistory.java:78)
        at org.jline.reader.impl.history.DefaultHistory.attach(DefaultHistory.java:66)
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:464)
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:383)
        at com.planet57.gshell.console.Console.work(Console.java:105)
        at com.planet57.gshell.console.Console.run(Console.java:83)
        at com.planet57.gshell.shell.ShellImpl.run(ShellImpl.java:247)
        at com.planet57.gshell.MainSupport.boot(MainSupport.java:310)
        at com.planet57.maven.shell.Main.main(Main.java:51)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.planet57.gshell.launcher.Launcher.launch(Launcher.java:74)
        at com.planet57.gshell.launcher.Launcher.run(Launcher.java:46)
        at com.planet57.gshell.launcher.Launcher.main(Launcher.java:37)
mosabua commented 7 years ago

I found that my history file contained this:

help
hostname
cd /opt/dev/
ls
cd github/takari/maven-wrapper/
mvn
mvn clean
mvn -v
edxit
exit
1493134191836:exit
1493134231528:test
1493134236167:mvn version
1493134249674:exit
1493134260140:exit
1493134453260:vim /home/manfred/.m2/mvnsh.history
1493134457827:vi /home/manfred/.m2/mvnsh.history
1493134460916:exit

Once I emptied it .. the stacktrace goes away. So maybe the issue only affects beta testers so to speak ;-)

jdillon commented 7 years ago

yup, its something I need to add to some release notes. jline3 history persistence is not compatible with previous version; removing the file should fix; but perhaps I can do something smarter.

mosabua commented 7 years ago

If you have control over reading the file in, you could just purge everything that does not start with a bunch of numbers.. or something like that. Probably fine to just lose that history.

jdillon commented 7 years ago

DefaultHistory impl is not terribly useful for doing stuff like that, so I may need to work with @gnodet to improve it a bit. Its also logging that as INFO which is also not ideal. But for now you can either rm the history file; ignore the error and I think next history --save may fix it; but I've not verified that yet.

UPDATE history --purge is what fixes this, history --save only flushes any pending lines to the end of the file.

mosabua commented 7 years ago

I just rm'ed the file. Feel free to close the issue or leave it open as a reminder.