This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 195bc35c41c4b728aa224dacf22cc9c1f39b4b88 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue May 9 20:32:29 2023 +0100 Fix IDE warnings --- java/org/apache/catalina/filters/RateLimitFilter.java | 12 ++++++++---- java/org/apache/catalina/util/TimeBucketCounter.java | 1 + .../apache/catalina/filters/TestRateLimitFilter.java | 19 +++++++++---------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/java/org/apache/catalina/filters/RateLimitFilter.java b/java/org/apache/catalina/filters/RateLimitFilter.java index e545381d58..7dd4f7a3a6 100644 --- a/java/org/apache/catalina/filters/RateLimitFilter.java +++ b/java/org/apache/catalina/filters/RateLimitFilter.java @@ -75,6 +75,8 @@ import org.apache.tomcat.util.res.StringManager; */ public class RateLimitFilter extends GenericFilter { + private static final long serialVersionUID = 1L; + /** * default duration in seconds */ @@ -198,8 +200,9 @@ public class RateLimitFilter extends GenericFilter { actualRequests = (int) Math.round(bucketCounter.getRatio() * bucketRequests); log.info(sm.getString("rateLimitFilter.initialized", - super.getFilterName(), bucketRequests, bucketDuration, getActualRequests(), - getActualDurationInSeconds(), (!enforce ? "Not " : "") + "enforcing") + super.getFilterName(), Integer.valueOf(bucketRequests), Integer.valueOf(bucketDuration), + Integer.valueOf(getActualRequests()), Integer.valueOf(getActualDurationInSeconds()), + (!enforce ? "Not " : "") + "enforcing") ); } @@ -210,13 +213,14 @@ public class RateLimitFilter extends GenericFilter { String ipAddr = request.getRemoteAddr(); int reqCount = bucketCounter.increment(ipAddr); - request.setAttribute(RATE_LIMIT_ATTRIBUTE_COUNT, reqCount); + request.setAttribute(RATE_LIMIT_ATTRIBUTE_COUNT, Integer.valueOf(reqCount)); if (enforce && (reqCount > actualRequests)) { ((HttpServletResponse) response).sendError(statusCode, statusMessage); log.warn(sm.getString("rateLimitFilter.maxRequestsExceeded", - super.getFilterName(), reqCount, ipAddr, getActualRequests(), getActualDurationInSeconds()) + super.getFilterName(), Integer.valueOf(reqCount), ipAddr, Integer.valueOf(getActualRequests()), + Integer.valueOf(getActualDurationInSeconds())) ); return; diff --git a/java/org/apache/catalina/util/TimeBucketCounter.java b/java/org/apache/catalina/util/TimeBucketCounter.java index bd5e70fcb4..4c1974242e 100644 --- a/java/org/apache/catalina/util/TimeBucketCounter.java +++ b/java/org/apache/catalina/util/TimeBucketCounter.java @@ -182,6 +182,7 @@ public class TimeBucketCounter { this.sleeptime = sleeptime; } + @SuppressWarnings("sync-override") @Override public void start() { isRunning = true; diff --git a/test/org/apache/catalina/filters/TestRateLimitFilter.java b/test/org/apache/catalina/filters/TestRateLimitFilter.java index f78b099e74..ecef77d0ab 100644 --- a/test/org/apache/catalina/filters/TestRateLimitFilter.java +++ b/test/org/apache/catalina/filters/TestRateLimitFilter.java @@ -27,20 +27,19 @@ import javax.servlet.FilterConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import org.junit.Assert; +import org.junit.Test; + import org.apache.catalina.Context; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.startup.Tomcat; -import org.apache.catalina.startup.TomcatBaseTest; import org.apache.catalina.filters.TestRemoteIpFilter.MockFilterChain; import org.apache.catalina.filters.TestRemoteIpFilter.MockHttpServletRequest; +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; import org.apache.tomcat.unittest.TesterResponse; import org.apache.tomcat.unittest.TesterServletContext; import org.apache.tomcat.util.descriptor.web.FilterDef; import org.apache.tomcat.util.descriptor.web.FilterMap; -import org.junit.Assert; -import org.junit.Test; - public class TestRateLimitFilter extends TomcatBaseTest { @Test @@ -63,7 +62,7 @@ public class TestRateLimitFilter extends TomcatBaseTest { int allowedRequests = (int) Math.round(rateLimitFilter.bucketCounter.getRatio() * bucketRequests); long sleepTime = rateLimitFilter.bucketCounter.getMillisUntilNextBucket(); - System.out.printf("Sleeping %d millis for the next time bucket to start\n", sleepTime); + System.out.printf("Sleeping %d millis for the next time bucket to start\n", Long.valueOf(sleepTime)); Thread.sleep(sleepTime); TestClient tc1 = new TestClient(rateLimitFilter, filterChain, "10.20.20.5", 200, 5); @@ -85,8 +84,7 @@ public class TestRateLimitFilter extends TomcatBaseTest { Assert.assertEquals(429, tc4.results[allowedRequests]); // subsequent requests dropped } - private RateLimitFilter testRateLimitFilter(FilterDef filterDef, Context root) - throws LifecycleException, IOException, ServletException { + private RateLimitFilter testRateLimitFilter(FilterDef filterDef, Context root) throws ServletException { RateLimitFilter rateLimitFilter = new RateLimitFilter(); filterDef.setFilterClass(RateLimitFilter.class.getName()); @@ -138,7 +136,8 @@ public class TestRateLimitFilter extends TomcatBaseTest { response.setRequest(request); filter.doFilter(request, response, filterChain); results[i] = response.getStatus(); - System.out.printf("%s %s: %s %d\n", ip, Instant.now(), i + 1, response.getStatus()); + System.out.printf("%s %s: %s %d\n", ip, Instant.now(), Integer.valueOf(i + 1), + Integer.valueOf(response.getStatus())); Thread.sleep(sleep); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org