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

PropertyUtils.setProperty Ignores Property Setter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5
    • None
    • None
    • None
    • Operating System: Windows XP
      Platform: Other

    • 14440

    Description

      When using PropertyUtils to set a property on an object that implements the
      Map interface, undesirable behavior can result. In my case, I was trying to
      use PropertyUtils (via BeanUtils) to set a property on an object of type
      org.apache.util.Criteria, which implements Map. Using
      PropertyUtils.setProperty ignores properties for which there is a legitimate
      setter, instead placing the value in the map. It would be more intuitive if
      the value were placed in the map only if no setter existed.

      Here is sample code that illustrates this problem:

      public class PropertyUtilsTest extends TestCase {
      private static final String TEST_VAL = "_test-val_";

      public void testPropUtils() {
      try

      { Criteria c = new Criteria(); PropertyUtils.setSimpleProperty(c, "dbName", TEST_VAL); assertEquals(TEST_VAL, c.getDbName()); }

      catch (Throwable t)

      { t.printStackTrace(); }

      }
      }

      In this case, Criteria implements a setDbName() method that will not be called
      by this code. This is somewhat confusing.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rg@onepercentsoftware.com Runako Godfrey
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: