Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-108285

There is no check if count is 0 when returning RenderRequestSummaryStatistics.getAverageTime()

Details

    Description

      com.liferay.portal.monitoring.internal.statistics.portlet.RenderRequestSummaryStatistics.getAverageTime() can throw ArithmeticException: Divide by zero, if the portal is monitored before the page is visited. In this case RenderRequestStatisticsSet is a zero-element array, and the execution never gets to the for loop, keeping the count variable zero.

      com.liferay.portal.monitoring.internal.statistics.portlet.RenderRequestSummaryStatistics.getAverageTime():

      public long getAverageTime() {
       long averageTime = 0;
      
       long count = 0;
      
       for (CompanyStatistics companyStatistics :
          _serverStatistics.getCompanyStatisticsSet()) {
      
       for (RequestStatistics requestStatistics :
           companyStatistics.getRenderRequestStatisticsSet()) {
      
          averageTime += requestStatistics.getAverageTime();
      
          count++;
         }
        }
      
       return averageTime / count;
       }
      

      There should be a validation if the count variable is not zero before dividing.

      Reproduction:
      1. Copy the Tomcat manager app to the webapps folder
      2. Start Tomcat, and during startup, before Liferay deploys hit http://localhost:8080/manager/jmxproxy/?qry=
      3. Wait until Tomcat starts up.

      You will get

      SEVERE [http-nio-8080-exec-3] org.apache.catalina.mbeans.MBeanDumper.dumpBeans Error getting attribute [AverageTime] for object name [com.liferay.portal.monitoring:classification=portlet_statistic,name=RenderRequestPortletManager] 
      javax.management.RuntimeMBeanException: java.lang.ArithmeticException: / by zero 

      Attachments

        Activity

          People

            summer.zhang Summer Zhang
            laszlo.pap Laszlo Pap
            Kiyoshi Lee Kiyoshi Lee
            Laszlo Pap Laszlo Pap
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              3 years, 14 weeks, 4 days ago

              Packages

                Version Package
                7.0.10.13 DXP SP13
                7.0.X
                7.1.10 DXP FP17
                7.1.10.4 SP4
                7.1.X
                7.2.10 DXP FP5
                7.2.10.2 DXP SP2
                7.2.X
                7.3.1 CE GA2
                7.3.2 CE GA3
                7.3.10 DXP GA1
                Master