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

    • Bug
    • Status: Closed
    • Could
    • Resolution: Fixed
    • None
    • None
    • 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);
      }
      

      Gliffy Diagrams

        Attachments

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: