You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2004/03/24 17:59:25 UTC

DO NOT REPLY [Bug 27910] New: - java.lang.NullPointerException at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:143)

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27910>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=27910

java.lang.NullPointerException at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:143)

           Summary: java.lang.NullPointerException at
                    org.apache.struts.validator.ValidatorForm.validate(Valid
                    atorForm.java:143)
           Product: Struts
           Version: 1.1 Final
          Platform: Other
               URL: http://cvs.apache.org/viewcvs.cgi/jakarta-
                    struts/src/share/org/apache/struts/validator/ValidatorFo
                    rm.java?rev=1.13&view=markup
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Validator Framework
        AssignedTo: struts-dev@jakarta.apache.org
        ReportedBy: hauser@acm.org


In my multi-step form wizard, hidden form fields may be a bad idea for security
reasons. Therefore, I keep a copy of the form in the session and incrementally
add the values gathered from the browser.
There arose even a scenario where it was advisable to set some values in that
form even without first doing a PropertyUtils.copyProperties from a form coming
from a browser. A subsequent .validate() then causes the above nullPointer
exception.

Suggestion: 
When doing the 
        ServletContext application = getServlet().getServletContext();
in the ValidatorForm, first test whether the "getServlet()" really returns other
than null and otherwise return a decent error message.

I am not fully clear why the problem arises, but I guess that ValidatorForm()
not having a constructor method is part of the reason for this.
Anyway, I got it working by extending my form as follows:
public class MyForm extends ValidatorForm
	public MyForm() {
		super();
	}
	public MyForm(ActionServlet servlet) {
		this();
		if (super.getServlet() == null) {
			if (servlet == null) {
				log.error("servlet == null");
			} else {
				super.setServlet(servlet);
				log.debug("set servlet: " + servlet);
			}
		} else {
			log.debug("super.getServlet(): " + super.getServlet());
		}

when creating the form, I call it with 
	MyForm myForm = new MyForm(getServlet());

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org