Details
-
Bug
-
Status: Closed
-
Resolution: Fixed
-
7.1.X, 7.2.X, Master
-
7.2.x, 7.1.x, 7.0.x
-
Committed
-
2
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