Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8210987

Extra newlines on Windows when running nsk jdb tests

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 12
    • 12
    • core-svc
    • None
    • b13

      We are seeing extra newlines on Windows while running jdb tests. For example:

      Sending command: stop in nsk.jdb.eval.eval001.eval001a.main
      reply[0]: Deferring breakpoint nsk.jdb.eval.eval001.eval001a.main.
      It will be set after the class is loaded.
      reply[1]:
      >
      Starting debuggee class
      Sending command: run
      reply[0]: run nsk.jdb.eval.eval001.eval001a
      reply[1]:
      Set uncaught java.lang.Throwable
      reply[2]:
      Set deferred uncaught java.lang.Throwable
      reply[3]:
      >
      reply[4]:
      VM Started: Set deferred breakpoint nsk.jdb.eval.eval001.eval001a.main
      reply[5]:

      reply[6]:
      Breakpoint hit: "thread=main", nsk.jdb.eval.eval001.eval001a.main(), line=38 bci=0
      reply[7]:
      38 System.exit(eval001.JCK_STATUS_BASE + _eval001a.runIt(args, System.out));
      reply[8]:

      reply[9]:
      main[1]

      Looks like every reply[x] line has an extra newline in it. I think it's due to the following code:

      I just stumbled across the following in Jdb.java. I think it might be the source of the extra newlines on windows:

          public static final String lineSeparator = System.getProperty("line.separator");

          public static String[] toStringArray (String string) {
              Vector<String> v = new Vector<String>();
              int ind;
              for (ind = 0; ind < string.length(); ) {
                  int i = string.indexOf(lineSeparator, ind);
                  if (i >= 0) {
                      v.add(string.substring(ind, i));
                      ind = i + 1;
                  } else {
                      v.add(string.substring(ind));
                      break;
                  }
              }
              String[] result = new String [v.size()];
              v.toArray(result);
              return result;
          }

      The problem is the "ind = i + 1" is attempting to skip over the line separator, but on windows it is two characters, not one, so the only the \r is skipped over, not the \n.

      There's a similar problem in sendCommand():

                  if (!jdbCommand.endsWith(lineSeparator)) {
                      logCmd = jdbCommand;
                      jdbCommand += lineSeparator;
                  } else {
                      // we don't want to log the line separator
                      logCmd = jdbCommand.substring(0, jdbCommand.length() - 1);
                  }

      I think the fix might be to just replace "1" with lineSeparator.length().

            cjplummer Chris Plummer
            cjplummer Chris Plummer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: