ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1306730 - /ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/RESTClientServlet.java
Date Thu, 29 Mar 2012 07:25:07 GMT
Author: jawi
Date: Thu Mar 29 07:25:07 2012
New Revision: 1306730

URL: http://svn.apache.org/viewvc?rev=1306730&view=rev
Log:
ACE-237: fixed possible exception when retrieving auditlog events for targets without any.

Modified:
    ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/RESTClientServlet.java

Modified: ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/RESTClientServlet.java
URL: http://svn.apache.org/viewvc/ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/RESTClientServlet.java?rev=1306730&r1=1306729&r2=1306730&view=diff
==============================================================================
--- ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/RESTClientServlet.java
(original)
+++ ace/trunk/ace-client-rest/src/main/java/org/apache/ace/client/rest/RESTClientServlet.java
Thu Mar 29 07:25:07 2012
@@ -192,23 +192,20 @@ public class RESTClientServlet extends H
 						else if (isTarget && ACTION_AUDITEVENTS.equals(action)) {
 							StatefulTargetObject target = (StatefulTargetObject) repositoryObject;
 							List<LogEvent> events = target.getAuditEvents();
+							
 							String startValue = req.getParameter("start");
 							String maxValue = req.getParameter("max");
+							
 							int start = (startValue == null) ? 0 : Integer.parseInt(startValue);
-							if (start < 0) {
-								start = 0;
-							}
-							if (start >= events.size()) {
-								start = events.size() - 1;
-							}
+							// ACE-237: ensure the start-value is a correctly bounded positive integer...
+							start = Math.max(0, Math.min(events.size() - 1, start));
+							
 							int max = (maxValue == null) ? 100 : Integer.parseInt(maxValue);
-							if (max < 1) {
-								max = 1;
-							}
-							int end = start + max;
-							if (end > events.size()) {
-								end = events.size();
-							}
+							// ACE-237: ensure the max- & end-values are correctly bounded...
+							max = Math.max(1, max);
+
+							int end = Math.min(events.size(), start + max);
+
 							List<LogEvent> selection = events.subList(start, end);
                         	resp.getWriter().println(m_gson.toJson(selection));
                         	return;



Mime
View raw message