[MAGNOLIA-3712] Off by one problem in LogViewerPage end() method. Created: 11/Apr/11  Updated: 04/Aug/15  Resolved: 04/Aug/15

Status: Closed
Project: Magnolia
Component/s: admininterface
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: Lee Haslup [X] (Inactive) Assignee: Philipp Bärfuss
Resolution: Outdated Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

I saw this problem in Magnolia 4.4


Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 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



 Comments   
Comment by Michael Mühlebach [ 04/Aug/15 ]

We're closing this issue as outdated as it was reported for 4.4.x or earlier versions which are no longer supported. Don't hesitate to reopen or create a new ticket in case this is still relevant and you'll experience it on 4.5.x or later versions.

Generated at Mon Feb 12 03:48:58 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.