#408 WebForm.setParameter throws NullPointerException on textarea

closed-accepted
None
7
2008-05-13
2008-04-29
No

When trying to set the value of a textarea, a NullPointerException is thrown:

java.lang.NullPointerException
at com.meterware.httpunit.TextFormControl.claimValue(FormControl.java:757)
at com.meterware.httpunit.FormParameter.setValues(FormParameter.java:100)
at com.meterware.httpunit.WebForm.setParameter(WebForm.java:632)
at com.meterware.httpunit.WebForm.setParameter(WebForm.java:621)
at org.ihc.phc.portlet.emc.TriagePortletTest.testCommentOverFlow(TriagePortletTest.java:89)

The culprit seems to be TextFormControl line758:

if (!(oldValue.equals( getValue() ))) sendOnChangeEvent();

There need to be a check for oldValue being null or the textarea control needs to not return null for its default value.

Discussion

  • Matthew O. Smith

    Logged In: YES
    user_id=539130
    Originator: YES

    form.getScriptableObject().setParameterValue("comments", repeat);

    This workaround seems to work.

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-29

    Logged In: YES
    user_id=1220573
    Originator: NO

    Dear httpunit user!

    Thank you for your bug report. We appreciate the time and effort you are putting into this.

    Please supply a testcase with the expected result for the bug report that you are asking a solution for and we'll look into implementing it. For a start you might want to get the trunk version from the subversion repository (see https://sourceforge.net/svn/?group_id=6550\)
    and have a look at the source code of some of the more than 700 JUnit based testcase in there.

    If you do not use or have subversion tool you can still directly browse our test cases via:
    http://httpunit.svn.sourceforge.net/viewvc/httpunit/trunk/httpunit/test/com/meterware/httpunit/
    Looking into one or more of the Junit Java source files
    should give you a clue on what a proper testcase for httpunit looks like, often you will probably only have to "clone" an existing testcase and modify it slightly to your needs.

    When you are ready you might want to attach the testcase (and if you already have started implementing a solution for it it also the actual code) to the patch section of the sourceforge.net tracker for patches of the httpunit project at
    https://sourceforge.net/tracker/?atid=306550&group_id=6550&func=browse.

    The main communication about further details of the development is via the httpunit developer mailinglist. You are most welcome to sign up via
    https://lists.sourceforge.net/lists/listinfo/httpunit-develop

    Yours
    The httpunit developer team

    (Russell, Wolfgang, Mark, Patrick and Tim as of 2008-04)

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-29

    Logged In: YES
    user_id=1220573
    Originator: NO

    Matthew

    thank you for the bug report. Would you please supply a few lines of JUnit test code so the handling of this bugs gets's quicker. The patch proposal seems o.k. to me.

    Yours
    Wolfgang

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-29
    • priority: 5 --> 7
    • assigned_to: nobody --> wolfgang_fahl
    • status: open --> open-accepted
     
  • Matthew O. Smith

    Logged In: YES
    user_id=539130
    Originator: YES

    Adding this method to WebFormTest will demonstrate the problem:

    /**
    * [ httpunit-Bugs-1954311 ] Set the value of a text area. Currently fails
    * if the textarea is empty to begin with.
    *
    * @throws Exception on failure
    */
    public void testTextArea() throws Exception {
    String fieldName = "comments";
    String comment = "My what a lovely dress that is";

    // Setting defaultValue to something other than an empty string makes
    // this test case pass.
    String defaultValue = "";

    defineWebPage("Default", "<form method=POST action = \"/servlet/Login\">" + "<textarea name='" + fieldName
    + "' row='10' cols='20'>" + defaultValue + "</textarea>" + "<br><Input type=submit value = \"Submit\">"
    + "</form>");

    WebResponse page = _wc.getResponse(getHostPath() + "/Default.html");
    WebForm form = page.getForms()[0];
    form.setParameter(fieldName, comment); // THIS LINE FAILS

    assertEquals(1, form.getParameterNames().length);

    WebRequest request = form.getRequest();
    assertEquals(comment, request.getParameter(fieldName));

    }

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-05-13
    • status: open-accepted --> closed-accepted
     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-05-13

    Logged In: YES
    user_id=1220573
    Originator: NO

    The change is now in the subversion repository and will be in the next build

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks