Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-550

DynaValidatorForm throws NullPointerException and ClassCastException

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1 Beta 1
    • Fix Version/s: 1.1 Family
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Operating System: All
      Platform: PC
    • Bugzilla Id:
      7751

      Description

      I have a DynaValidatorForm declared in the form-bean like so:
      <form-bean name="testDynaForm"
      type="org.apache.struts.validator.DynaValidatorForm">
      <form-property name="username" type="java.lang.String" />
      <form-property name="password" type="java.lang.String" />
      <form-property name="address" type="java.lang.String" />
      <form-property name="city" type="java.lang.String" />
      </form-bean>
      It works great when DynaValidatorForm is a DynaActionForm... But, as soon as I
      swap it with DynaValidatorForm it throws the attached (error1) error. Also,
      when I have the type="org.apache.struts.action.DynaActionForm" and try to cast
      it to a DynaValidatorForm i get a ClassCastException error.

      ========================== error1 ====================================
      java.lang.NullPointerException
      at org.apache.struts.action.DynaActionForm.getDynaProperty
      (DynaActionForm.java:539)
      at org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:357)
      at org.apache.struts.action.DynaActionForm.reset
      (DynaActionForm.java:158)
      at org.apache.struts.validator.DynaValidatorForm.reset
      (DynaValidatorForm.java:357)
      at org.apache.struts.util.RequestUtils.createActionForm
      (RequestUtils.java:618)
      at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:606)
      at org.apache.jsp.testdynaform$jsp._jspService(testdynaform$jsp.java:76)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service
      (JspServlet.java:202)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile
      (JspServlet.java:382)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
      (ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter
      (ApplicationFilterChain.java:193)
      at ws.phase.security.filter.URLFilter.doFilter(URLFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
      (ApplicationFilterChain.java:213)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter
      (ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke
      (StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke
      (StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke
      (StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke
      (CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke
      (StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke
      (StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke
      (StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke
      (ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke
      (ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke
      (AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke
      (StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke
      (StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke
      (StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.ajp.tomcat4.Ajp13Processor.process
      (Ajp13Processor.java:429)
      at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:495)
      at java.lang.Thread.run(Thread.java:536)
      ========================== error1 ====================================

      ========================== error2 ====================================

      java.lang.ClassCastException: org.apache.struts.action.DynaActionForm
      at ws.phase.test.TestDynaAction.execute(TestDynaAction.java:59)
      at org.apache.struts.action.RequestProcessor.processActionPerform
      (RequestProcessor.java:437)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:264)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1109)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:470)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
      (ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter
      (ApplicationFilterChain.java:193)
      at ws.phase.security.filter.URLFilter.doFilter(URLFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
      (ApplicationFilterChain.java:213)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter
      (ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke
      (StandardWrapperValve.java:243)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke
      (StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke
      (CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke
      (StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke
      (ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke
      (ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke
      (StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext
      (StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:429)
      at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:495)
      at java.lang.Thread.run(Thread.java:536)
      ========================== error2 ====================================

      ========================== ActionClassCode ====================================
      /*

      • LoginAction.java
        *
      • Created on October 12, 2001, 12:14 AM
        */

      package ws.phase.test;

      import ws.phase.security.form.LoginForm;

      import ws.phase.test.*;

      import ws.phase.security.logicbeans.SQLAuthenticatorBean;

      import ws.phase.security.databeans.RequestedPathBean;
      import ws.phase.security.databeans.LoginRedirectBean;
      import ws.phase.security.databeans.RealmBean;
      import ws.phase.security.databeans.UserBean;

      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import javax.servlet.http.HttpSession;
      import javax.servlet.ServletContext;
      import javax.servlet.http.Cookie;
      import javax.servlet.RequestDispatcher;
      import javax.servlet.ServletException;

      import java.security.Principal;

      import org.apache.struts.action.*;
      import org.apache.struts.util.RequestUtils;

      import org.apache.struts.validator.DynaValidatorForm;
      import org.apache.struts.validator.DynaValidatorActionForm;

      import org.apache.commons.beanutils.DynaProperty;
      import org.apache.commons.beanutils.DynaClass;

      import java.io.*;
      import java.util.*;
      import java.net.*;
      /**
      *

      • @author Administrator
      • @version
        */
        public class TestDynaAction extends Action{
        HttpServletResponse response = null;

      public ActionForward execute(ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      {
      DynaValidatorForm dvaf = null;

      this.response = response;
      try

      { dvaf = (DynaValidatorForm)form; }

      catch(Exception ex){
      try

      { PrintWriter pw = response.getWriter(); ex.printStackTrace(pw); pw.flush(); pw.close(); }

      catch (IOException ioex){
      }

      }

      ActionErrors ae = dvaf.validate(mapping,request);
      servlet.log("Validate");
      if(!ae.empty())

      { servlet.log("Got Errors"); saveErrors(request,ae); servlet.log("Saved Errors"); servlet.log(mapping.getInput()); return new ActionForward(mapping.getInput()); }

      DynaClass dc = dvaf.getDynaClass();
      DynaProperty[] dp = dc.getDynaProperties();
      int length = dp.length;
      for(int x = 0; x<length; x++)

      { String name = dp[x].getName(); String value = (String)dvaf.get(name); servlet.log("DYNA PROP: " + name + ":" + value); }

      return mapping.findForward("auth");
      }
      }
      ========================== ActionClassCode ====================================

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mail@phase.ws Brandon Goodin
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: