Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.9.3
-
None
-
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")); } }