NPE in BeforeAfterMethod
------------------------

                 Key: STS-278
                 URL: http://mc4j.org/jira/browse/STS-278
             Project: Stripes
          Issue Type: Bug
          Components: ActionBean Dispatching
    Affects Versions: Release 1.4.1
            Reporter: Aaron Porter
         Assigned To: Tim Fennell


If I have both the BeforeAfterMethodInterceptor and Nic's SecurityInterceptor 
specified in web.xml I get a NPE at BeforeAfterMethodInterceptor.java:111 
because the return of context.getActionBean() isn't checked for null. The 
@Before handler directly above works correctly because it is checking for null.

This fixes it:

Index: BeforeAfterMethodInterceptor.java
===================================================================
--- BeforeAfterMethodInterceptor.java   (revision 424)
+++ BeforeAfterMethodInterceptor.java   (working copy)
@@ -106,21 +106,23 @@
         // Continue on and execute other filters and the lifecycle code
         resolution = context.proceed();

-        // Run After filter methods (if any)
-        ActionBean bean = context.getActionBean();
-               FilterMethods filterMethods = getFilterMethods(bean.getClass());
-               List<Method> afterMethods = 
filterMethods.getAfterMethods(stage);
+        // Run @After methods, as long as there's a bean to run them on
+        if (context.getActionBean() != null) {
+            ActionBean bean = context.getActionBean();
+            FilterMethods filterMethods = getFilterMethods(bean.getClass());
+            List<Method> afterMethods = filterMethods.getAfterMethods(stage);

-        Resolution overrideResolution = null;
-        for (Method method : afterMethods) {
-            overrideResolution = invoke(bean, method, stage, After.class);
-            if (overrideResolution != null) {
-                return overrideResolution;
+            Resolution overrideResolution = null;
+            for (Method method : afterMethods) {
+                overrideResolution = invoke(bean, method, stage, After.class);
+                if (overrideResolution != null) {
+                    return overrideResolution;
+                }
             }
         }

-               return resolution;
-       }
+        return resolution;
+    }



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to