You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/09/30 18:50:57 UTC
(tomcat) 04/11: Use an instanceof check when instantiating the configured rateLimitClassName in RateLimitFilter.init() so a class that does not implement RateLimiter produces the intended ServletException rather than a raw ClassCastException
This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 1eaae2e080b97ebf9acaf94ead170cfda83ef0f1
Author: opencode <re...@apache.org>
AuthorDate: Wed Sep 30 16:24:53 2026 +0200
Use an instanceof check when instantiating the configured rateLimitClassName in RateLimitFilter.init() so a class that does not implement RateLimiter produces the intended ServletException rather than a raw ClassCastException
---
java/org/apache/catalina/filters/RateLimitFilter.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/catalina/filters/RateLimitFilter.java b/java/org/apache/catalina/filters/RateLimitFilter.java
index 8884921bda..cefc14ebcb 100644
--- a/java/org/apache/catalina/filters/RateLimitFilter.java
+++ b/java/org/apache/catalina/filters/RateLimitFilter.java
@@ -254,7 +254,12 @@ public class RateLimitFilter extends FilterBase {
super.init(filterConfig);
try {
- rateLimiter = (RateLimiter) Class.forName(rateLimitClassName).getConstructor().newInstance();
+ Object instance = Class.forName(rateLimitClassName).getConstructor().newInstance();
+ if (instance instanceof RateLimiter limiter) {
+ rateLimiter = limiter;
+ } else {
+ throw new ServletException(sm.getString("rateLimitFilter.classNotFound", rateLimitClassName));
+ }
} catch (ReflectiveOperationException e) {
throw new ServletException(sm.getString("rateLimitFilter.classNotFound", rateLimitClassName), e);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org