JDK-8261692 : Bugs in clhsdb history support
  • Type: Bug
  • Component: hotspot
  • Sub-Component: svc-agent
  • Affected Version: 17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-02-13
  • Updated: 2021-03-02
  • Resolved: 2021-02-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b11Fixed
Related Reports
Blocks :  
Description
Much like unix shells, clhsdb supports recalling commands from the history, and much like unix shells, relies on the '!' character to indicate a history reference. However, it has three bugs that need to be addressed.

The first issue is that !<cmd> matches every <cmd> in the history, not just the most recent occurrence. This makes the history support useless once the command is in the history more than once. Shell history matching only uses the most recent match. clhsdb should do the same.

hsdb> verbose true
hsdb> !ver 
verbose true
hsdb> !ver
verbose trueverbose true
Usage: verbose true | false

The second issue is that a '!' anywhere in the command will trigger history matching, but provides no way to disable it with quoting. This becomes problematic when you want to pass an argument that has an '!', which is the case with the new findysm support I'm adding with JDK-8261098. On windows I had to add a '!' to the symbol, and it took me a long time to figure out why the '!' and everything after it seemed to be getting stripped.

hsdb> echo true
hsdb> echo true
+ echo true
hsdb> echo !true 
+ echo   <-- it tried to match on "true", but didn't find any matches
echo is true
hsdb> echo !echo
+ echo echo echo trueecho true   <-- tried to match on "echo" and found some matches
Usage: echo [ true | false ]

It looks like this is supported behavior by unix shells also. The work around in unix shells is to quote the '!' with a '\'. However, clhsdb does not support this. It will need to if we want to allow clhsdb command arguments to contain a '!'.

The 3rd issue is when there is more than one '!' given in the command. Upon processing the second '!' you get an exception:

hsdb> echo one two three
Usage: echo [ true | false ]
hsdb> echo !$ !$
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 7, end 1, length 10

This is due to the following code:

                    if (m.start() > start) {
                        result.append(ln.substring(start, m.start() - start));
                    }

This code is suppose to capture any text that did not match the "historyPattern". So in the above example on the first pass it would capture "echo " and on the second pass just the " ". The problem is that it is subtracting "start" from the 2nd argument, which is suppose to be the end of the range to copy, not the length. This works fine on the first pass since "start" is 0, but on the second pass is causes "end" to be 1 instead of 8.
Comments
Changeset: 18188c2a Author: Chris Plummer <cjplummer@openjdk.org> Date: 2021-02-20 23:19:41 +0000 URL: https://git.openjdk.java.net/jdk/commit/18188c2a
20-02-2021