You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Alexander Klimetschek (JIRA)" <ji...@apache.org> on 2009/04/14 15:19:14 UTC

[jira] Created: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

SlingSafeMethodsServlet swallows ClassCastExceptions
----------------------------------------------------

                 Key: SLING-921
                 URL: https://issues.apache.org/jira/browse/SLING-921
             Project: Sling
          Issue Type: Improvement
          Components: API
            Reporter: Alexander Klimetschek
            Priority: Minor


SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".

But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.

This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Klimetschek updated SLING-921:
----------------------------------------

    Attachment: SLING-921.patch

This patch uses instanceof for the check for the sling specific interfaces and "passes through" any ClassCastException, so that it will be displayed properly in both the log and the standard error response html.

> SlingSafeMethodsServlet swallows ClassCastExceptions
> ----------------------------------------------------
>
>                 Key: SLING-921
>                 URL: https://issues.apache.org/jira/browse/SLING-921
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>            Reporter: Alexander Klimetschek
>            Priority: Minor
>
> SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".
> But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.
> This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Klimetschek updated SLING-921:
----------------------------------------

    Attachment:     (was: SLING-921.patch)

> SlingSafeMethodsServlet swallows ClassCastExceptions
> ----------------------------------------------------
>
>                 Key: SLING-921
>                 URL: https://issues.apache.org/jira/browse/SLING-921
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>            Reporter: Alexander Klimetschek
>            Priority: Minor
>
> SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".
> But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.
> This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Klimetschek closed SLING-921.
---------------------------------------


And I like to handle the "failure" cases early in the method to have the normal and expected code path to be clearly visible without many nested if statements that make the simple stuff look complicated. This often involves negative statements at the top.

> SlingSafeMethodsServlet swallows ClassCastExceptions
> ----------------------------------------------------
>
>                 Key: SLING-921
>                 URL: https://issues.apache.org/jira/browse/SLING-921
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: API 2.0.2
>            Reporter: Alexander Klimetschek
>            Assignee: Felix Meschberger
>            Priority: Minor
>             Fix For: API 2.0.4
>
>         Attachments: SLING-921.patch
>
>
> SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".
> But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.
> This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger updated SLING-921:
------------------------------------

    Affects Version/s: API 2.0.2

> SlingSafeMethodsServlet swallows ClassCastExceptions
> ----------------------------------------------------
>
>                 Key: SLING-921
>                 URL: https://issues.apache.org/jira/browse/SLING-921
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: API 2.0.2
>            Reporter: Alexander Klimetschek
>            Assignee: Felix Meschberger
>            Priority: Minor
>             Fix For: API 2.0.4
>
>         Attachments: SLING-921.patch
>
>
> SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".
> But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.
> This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger resolved SLING-921.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: API 2.0.4

Thanks for providing the patch.

I have applied it slightly modified (I more like positive tests than negative ones ;-) ) in Rev. 764775

If this works for you, please close this issue. Thanks.

> SlingSafeMethodsServlet swallows ClassCastExceptions
> ----------------------------------------------------
>
>                 Key: SLING-921
>                 URL: https://issues.apache.org/jira/browse/SLING-921
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>    Affects Versions: API 2.0.2
>            Reporter: Alexander Klimetschek
>            Assignee: Felix Meschberger
>            Priority: Minor
>             Fix For: API 2.0.4
>
>         Attachments: SLING-921.patch
>
>
> SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".
> But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.
> This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger reassigned SLING-921:
---------------------------------------

    Assignee: Felix Meschberger

> SlingSafeMethodsServlet swallows ClassCastExceptions
> ----------------------------------------------------
>
>                 Key: SLING-921
>                 URL: https://issues.apache.org/jira/browse/SLING-921
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>            Reporter: Alexander Klimetschek
>            Assignee: Felix Meschberger
>            Priority: Minor
>         Attachments: SLING-921.patch
>
>
> SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".
> But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.
> This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (SLING-921) SlingSafeMethodsServlet swallows ClassCastExceptions

Posted by "Alexander Klimetschek (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-921?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alexander Klimetschek updated SLING-921:
----------------------------------------

    Attachment: SLING-921.patch

Re-attaching the same patch, now with ASF license (clicked the wrong radio button in the first attempt ;-)).

> SlingSafeMethodsServlet swallows ClassCastExceptions
> ----------------------------------------------------
>
>                 Key: SLING-921
>                 URL: https://issues.apache.org/jira/browse/SLING-921
>             Project: Sling
>          Issue Type: Improvement
>          Components: API
>            Reporter: Alexander Klimetschek
>            Priority: Minor
>         Attachments: SLING-921.patch
>
>
> SlingSafeMethodsServlet.service(ServletRequest req, ServletResponse res) tries to cast request & response objects to Sling's specific request & response interfaces. Therefore it catches a ClassCastException for those (seldom) cases where the servlet is erroneously used in a non-Sling environment and throws a ServletException in that case with the message "Not a Sling HTTP request/response".
> But this also swallows class-cast exceptions thrown inside custom servlets that inherit from SlingSafeMethodsServlet. The stacktrace is lost and the error message is wrong in this case.
> This can be fixed by doing an instanceof check instead of the try/catch block.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.