Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-3712

Off by one problem in LogViewerPage end() method.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Outdated
    • Neutral
    • None
    • None
    • admininterface
    • None
    • I saw this problem in Magnolia 4.4

    Description

      If you try to view the last page ( click ">>" ) in a logfile that is some exact multiple of the page size in lines (eg 100 lines, 150 lines, etc.) the log viewer will display "File is Empty " and suppress the page navigation information and controls.

      The problem is in the end() method which reads

          public String end() {
              if (this.fileSizeInLines > this.maxNumLinesPerPage) {
                  this.currentPosition = this.fileSizeInLines - (this.fileSizeInLines % this.maxNumLinesPerPage);
              } else {
                  currentPosition = 0;
              }
              displayFileContent();
              return VIEW_SHOW;
          }
      

      The problem is that if fileSizeInLines is an even multiple of maxNumLinesPerPage then the modulo function returns zero and currentPosition is set to fileSizeInLines which, since the line offset is zero-based is the first line after the end of the log file.

      The following implementation should correct this problem and is computationally simpler into the bargain.

          public String end() {
              if (this.fileSizeInLines > this.maxNumLinesPerPage) {
                  this.currentPosition = ((this.fileSizeInLines - 1L) / this.maxNumLinesPerPage) * this.maxNumLinesPerPage ;
              } else {
                  currentPosition = 0;
              }
              displayFileContent();
              return VIEW_SHOW;
          }
      

      Lee

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              pbaerfuss Philipp Bärfuss
              bigleeh Lee Haslup [X] (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Bug DoR
                  Task DoD