You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Christopher K. St. John" <ck...@distributopia.com> on 2001/12/28 21:18:24 UTC

[PATCH][4.0] remove spurious casts in ApplicationFilterChain

 The "fall off the end of the chain" code in
ApplicationFilterChain.internalDoFilter checks if the
passed in request and response are HttpServletRequest/
Response objects. Based on the test, it casts the 
objects and invokes servlet.service(). However, since
the servlet member has a static type of javax.servlet.Servlet,
the exact same method is called in both cases. The code
operates correctly (since the non-http version of the 
service() method eventually invokes the correct version
of service()), but the test and cast are redundant and
confusing. The following patch removes them:


Index: ApplicationFilterChain.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java,v
retrieving revision 1.11
diff -u -r1.11 ApplicationFilterChain.java
--- ApplicationFilterChain.java 2001/10/11 23:30:58     1.11
+++ ApplicationFilterChain.java 2001/12/28 19:06:24
@@ -242,13 +242,7 @@
         try {
             support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
                                       servlet, request, response);
-            if ((request instanceof HttpServletRequest) &&
-                (response instanceof HttpServletResponse)) {
-                servlet.service((HttpServletRequest) request,
-                                (HttpServletResponse) response);
-            } else {
-                servlet.service(request, response);
-            }
+            servlet.service(request, response);
             support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
                                       servlet, request, response);
         } catch (IOException e) {




-- 
Christopher St. John cks@distributopia.com
DistribuTopia http://www.distributopia.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PATCH][4.0] remove spurious casts in ApplicationFilterChain

Posted by Daniel Rall <dl...@finemaltcoding.com>.
+1, old code was redundant.  Java should find the right method to call
based on object--not reference--type.

"Christopher K. St. John" <ck...@distributopia.com> writes:

>  The "fall off the end of the chain" code in
> ApplicationFilterChain.internalDoFilter checks if the
> passed in request and response are HttpServletRequest/
> Response objects. Based on the test, it casts the 
> objects and invokes servlet.service(). However, since
> the servlet member has a static type of javax.servlet.Servlet,
> the exact same method is called in both cases. The code
> operates correctly (since the non-http version of the 
> service() method eventually invokes the correct version
> of service()), but the test and cast are redundant and
> confusing. The following patch removes them:
>
>
> Index: ApplicationFilterChain.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationFilterChain.java,v
> retrieving revision 1.11
> diff -u -r1.11 ApplicationFilterChain.java
> --- ApplicationFilterChain.java 2001/10/11 23:30:58     1.11
> +++ ApplicationFilterChain.java 2001/12/28 19:06:24
> @@ -242,13 +242,7 @@
>          try {
>              support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
>                                        servlet, request, response);
> -            if ((request instanceof HttpServletRequest) &&
> -                (response instanceof HttpServletResponse)) {
> -                servlet.service((HttpServletRequest) request,
> -                                (HttpServletResponse) response);
> -            } else {
> -                servlet.service(request, response);
> -            }
> +            servlet.service(request, response);
>              support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
>                                        servlet, request, response);
>          } catch (IOException e) {

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>