tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 48060] New: wrong implementation of peek() method of JIoEndpoint.WorkerStack class
Date Tue, 27 Oct 2009 00:36:04 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=48060

           Summary: wrong implementation of peek() method of
                    JIoEndpoint.WorkerStack class
           Product: Tomcat 7
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: qingyang.xu@qunar.com


/**
         * Get the first object out of the queue, Return null if the queue
         * is empty.
         */
        public Worker peek() {
            return workers[end];
        }


should be:

         /**
         * Get the first object out of the queue, Return null if the queue
         * is empty.
         */
        public Worker peek() {
            if (end > 0) {
                return workers[end - 1];
            }
            return null;
        }

please refer to the pop() method (apart from pop()'s side effect, pop() and
peek() should return the same result):

        /**
         * Get the first object out of the queue. Return null if the queue
         * is empty. 
         */
        public Worker pop() {
            if (end > 0) {
                return workers[--end];
            }
            return null;
        }


'end' denotes the index beyond the last element, not the index of the last
element itself. That is why the variable of 'end' is assigned a zero value at
first.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message