Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-519

setProperty fails silently on null maps

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.9.3
    • None
    • Bean / Property Utils
    • None

    Description

      Adding an element to a null map with BeanUtils.setProperty() neither result in an automatically instantiated Map containing the specified element, nor to a NullPointerException. The method simply fails and returns silently. If the map isn't created on the fly an exception should be thrown at least.

      Here is a test case illustrating the issue:

      public class BeanUtilsTest extends TestCase {
          
          private static class Bean {
              public Map<String, String> elements;
          }
          
          public void testSetPropertyWithNullMap() throws Exception {
              Bean b = new Bean();
              assertNull(b.elements);
              
              BeanUtils.setProperty(b, "elements(FOO)", "BAR");
      
              assertNotNull("Map is still null after calling BeanUtils.setProperty()", b.elements);
              assertTrue("Element not found", b.elements.containsKey("FOO"));
          }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            ebourg Emmanuel Bourg
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: