Commits

Anonymous committed 44edf13

Issue number: WWW-486
Avoid potential IndexOutOfBoundsException.

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@390573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (1)

src/java/com/opensymphony/webwork/views/jsp/ActionTag.java

     }
 
     String buildNamespace() {
-        String namespace = "";
-        ActionInvocation invocation = null;
         ActionContext context = new ActionContext(getStack().getContext());
-
-        if (context != null) {
-            invocation = context.getActionInvocation();
-        }
+        ActionInvocation invocation = context.getActionInvocation();
 
         if (invocation == null) {
             // Path is always original path, even if it is included in page with another path
             HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
-
             String actionPath = request.getServletPath();
-            namespace = ServletDispatcher.getNamespaceFromServletPath(actionPath);
+            return ServletDispatcher.getNamespaceFromServletPath(actionPath);
         } else {
-            namespace = invocation.getProxy().getNamespace();
+            return invocation.getProxy().getNamespace();
         }
-
-        return namespace;
     }
 
     private Map createExtraContext() {
     }
 
     /**
-     * execute the requested action.  if no
-     * namespace is provided, we'll attempt to derive a namespace using buildNamespace().  the ActionProxy and the
-     * namespace will be saved into the instance variables proxy and namespace respectively.
+     * Execute the requested action.  If no namespace is provided, we'll
+     * attempt to derive a namespace using buildNamespace().  The ActionProxy
+     * and the namespace will be saved into the instance variables proxy and
+     * namespace respectively.
      * @see #buildNamespace
      */
     private void executeAction() throws JspException {
-        String namespace = null;
-        if (namespaceAttr == null) {
-            namespace = buildNamespace();
-        } else {
-            namespace = namespaceAttr;
-        }
 
-        OgnlValueStack stack = getStack();
         String actualName = findString(name);
-
         if (actualName == null) {
             throw new JspException("Unable to find value for name " + name);
         }
 
+        String namespace;
+        if (namespaceAttr == null) {
+            namespace = buildNamespace();
+        } else {
+            namespace = namespaceAttr;
+        }
+
         // execute at this point, after params have been set
         try {
-            Object top = null;
             ActionContext actionContext = ActionContext.getContext();
+            OgnlValueStack stack = getStack();
 
+            Object top = null;
             if ((stack != null) && (stack.size() > 0)) {
                 top = stack.peek();
             }
                 if ((stack != null) && (stack.size() > 1)) {
                     Object newTop = stack.peek();
 
-                    while (!(newTop == null) && !newTop.equals(top)) {
+                    while ((newTop != null) && !newTop.equals(top)) {
                         stack.pop();
-                        newTop = stack.peek();
+
+                        if (stack.size() == 0) {
+                            newTop = null;
+                        } else {
+                            newTop = stack.peek();
+                        }
                     }
                 }
             }