Uploaded image for project: 'XForms Module'
  1. XForms Module
  2. XFRM-207

Setting node value with null node and non-null value results in unexpected behavior

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Could
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
    • Complexity:
      Low

      Description

      Currently, in XFormBuilder there is a function setNodeValue(Element, String) that takes a node and a value. If a null node is passed in along a non-null value, calling getTextValue results in unexpected behavior. SetNodeValue should not only check if the String value is null, but also if the element passed in is null (in case a user calls a method later that requires a non-null node). I have written two tests, one that shows normal behavior, and one that throws an exception for a NullPointer:

      @Test
      public void shouldSuccessfullyGetTextValueFromNonNullNode() throws Exception{
      	
              Element elm = new Element();
      	XformBuilder.setNodeValue(elm, "1");
      	String val = XformBuilder.getTextValue(elm);
      
      	Assert.assertEquals("1", val);
      }
      
      @Test
      public void shouldThrowNullPointerExceptionIfGettingTextFromNullNode() throws Exception {
      	boolean thrown = false;
      
       	try {
      	      Element elm = null;
      	      XformBuilder.setNodeValue(elm, "1");
      	      String val = XformBuilder.getTextValue(elm);
       		
      	} catch (NullPointerException e) {
      		thrown = true;
        	}
        	Assert.assertTrue(thrown);
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            hirschf2 Kyle Hirschfelder
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: