infinite loop in struts form
This code in a Struts Action Form bean will generate an infinite loop and StackOverflow error if any of the 'if' conditions are triggered. If i comment out the lines beginning with 'error.add', the form will not generate an infinite loop. So I believe the problem is with adding ActionMessages to ActionErrors errors. I am not sure how to prevent this code from generating an infinite loop/StackOverflow error. The code is
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request){
ActionErrors errors =new ActionErrors();
boolean ok =true;
if (getQues() ==null || getQues().length() < 1){
errors.add("ques",new ActionMessage("error.ques.required"));
ok =false;
}
if (getAns() ==null || getAns().length() < 1){
errors.add("ans",new ActionMessage("error.ans.required"));
ok =false;
}
if (ok){
if (getQues().length() < minQuestionLength || getQues().length() > maxQuestionLength){
errors.add("queslength",new ActionMessage("error.ques.length"));
}
if (getAns().length() < minAnswerLength || getAns().length() > maxAnswerLength){
errors.add("anslength",new ActionMessage("error.ans.length"));
}
}
return errors;
}
My struts-config.xml looks like
<form-beans>
<form-bean name="newQAForm" type="updacct.form.NewQAForm"/>
<form-bean name="newPasswordForm" type="updacct.form.NewPasswordForm"/>
<form-bean name="answerForm" type="updacct.form.AnswerForm"/>
<form-bean name="idInfoForm" type="updacct.form.IdInfoForm"/>
</form-beans>
<action-mappings>
<action path="/useIDInfoQA"
name="idInfoForm"
input="/jsp/doChangeQAIDPage.jsp"
scope="request"
type="updacct.action.UseIDInfoAction">
<forward name="haspassword" path="/jsp/doChangeQAQASetPage.jsp" />
<forward name="nopassword" path="/jsp/doChangeQAQAPage.jsp" />
<forward name="dataError" path="/jsp/doChangeQAIDPage.jsp"/>
<forward name="noMatch" path="/jsp/noMatch.jsp"/>
</action>
<action path="/useAnswerQA"
name="answerForm"
input="/jsp/doChangeQAQAPage.jsp"
scope="request"
type="updacct.action.UseAnswerAction">
<forward name="success" path="/jsp/doChangeQAQASetPage.jsp" />
<forward name="failure" path="/jsp/doChangeQAQAPage.jsp" />
</action>
<action
path="/setQA"
input="/setQA.do"
name="newQAForm"
scope="request"
type="updacct.action.SetQAAction">
<forward name="success" path="/jsp/doChangeQASuccessPage.jsp" />
<forward name="answerError" path="/jsp/doChangeQAQASetPage.jsp" />
<forward name="dataError" path="/jsp/doChangeQAQASetPage.jsp"/>
</action>
Can anyone point me in the right direction re: how to troubleshoot this? I've been looking at this for quite a while and I'm not sure what is wrong with my application. Thanks.

