spring-projects / spring-shell

Spring based shell
http://projects.spring.io/spring-shell/
Apache License 2.0
719 stars 395 forks source link

TerminalUI may get race condition for display update #1039

Closed jvalkeal closed 4 months ago

jvalkeal commented 4 months ago

Running catalog app in vscode on windows may throw:

start catalog:

java.util.ConcurrentModificationException: null
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1221) ~[na:na]
        at org.jline.utils.Display.cost(Display.java:367) ~[jline-terminal-3.25.1.jar:na]
        at org.jline.utils.Display.perform(Display.java:353) ~[jline-terminal-3.25.1.jar:na]
        at org.jline.utils.Display.moveVisualCursorTo(Display.java:439) ~[jline-terminal-3.25.1.jar:na]
        at org.jline.utils.Display.update(Display.java:263) ~[jline-terminal-3.25.1.jar:na]
        at org.jline.utils.Display.update(Display.java:107) ~[jline-terminal-3.25.1.jar:na]
        at org.springframework.shell.component.view.TerminalUI.display(TerminalUI.java:293) ~[main/:na]
        at org.springframework.shell.component.view.TerminalUI.loop(TerminalUI.java:394) ~[main/:na]
        at org.springframework.shell.component.view.TerminalUI.run(TerminalUI.java:121) ~[main/:na]
        at org.springframework.shell.samples.catalog.Catalog.run(Catalog.java:150) ~[main/:na]
        at org.springframework.shell.samples.catalog.CatalogCommand.catalog(CatalogCommand.java:47) ~[main/:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
        at org.springframework.shell.command.invocation.InvocableShellMethod.doInvoke(InvocableShellMethod.java:306) ~[main/:na]
        at org.springframework.shell.command.invocation.InvocableShellMethod.invoke(InvocableShellMethod.java:232) ~[main/:na]
        at org.springframework.shell.command.CommandExecution$DefaultCommandExecution.evaluate(CommandExecution.java:230) ~[main/:na]
        at org.springframework.shell.Shell.evaluate(Shell.java:248) ~[main/:na]
        at org.springframework.shell.Shell.run(Shell.java:159) ~[main/:na]

While not seen on linux this may be specific for windows. Screen update may from events like screen size change. We probably need to synchronise update and see if it makes a difference.

jvalkeal commented 4 months ago

Definitely a race condition as mostly the ui in catalog app is messed up, which can be fixed by resize window but if error happens with initial update when app starts then whole process fails.