Commons BeanUtils
  1. Commons BeanUtils
  2. BEANUTILS-33

Can't use "dot" in mapped properties for setProperty or getPropertyDescriptor

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.0
    • Fix Version/s: 1.8.0
    • Component/s: Expression Syntax
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10478

      fixed this problem for PropertyUtils.getProperty(); However, the problem remains
      for setProperty and getPropertyDescriptor.

      I have fixed this against 1.6.1

        Issue Links

          Activity

          Hide
          Eoin Curran added a comment -

          Created an attachment (id=11449)
          Patch to fix

          Show
          Eoin Curran added a comment - Created an attachment (id=11449) Patch to fix
          Hide
          Eoin Curran added a comment -

          Forgot to include test case. in PropertyUtilsTestCase:

          /**

          • Test setting mapped values with periods in the key.
            */
            public void testSetMappedPeriods() throws Exception { // String value PropertyUtils.setNestedProperty(bean,"mappedProperty(key.with.a.dot)", "Special Value"); assertEquals("Can retrieve directly", "Special Value", bean.getMappedProperty("key.with.a.dot")); // Object value PropertyUtils.setNestedProperty(bean,"mappedObjects(nested.property)", new TestBean()); assertNotNull("Can retrieve directly", bean.getMappedObjects("nested.property")); }

          public void testGetPropertyTypeMappedPeriods() throws NoSuchMethodException,
          IllegalAccessException, InvocationTargetException

          { PropertyUtils.setNestedProperty(bean,"mappedObjects(nested.property)", new TestBean()); assertEquals(String.class,PropertyUtils.getPropertyType(bean,"mappedObjects(nested.property).stringProperty")); }

          produces:

          java.lang.IllegalArgumentException: Invalid mapped property 'mappedProperty(key'
          at
          org.apache.commons.beanutils.PropertyUtils.getMappedProperty(PropertyUtils.java:564)
          at
          org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1651)
          at
          org.apache.commons.beanutils.PropertyUtilsTestCase.testSetMappedPeriods(PropertyUtilsTestCase.java:1118)

          java.lang.IllegalArgumentException: Invalid mapped property 'mappedObjects(nested'
          at
          org.apache.commons.beanutils.PropertyUtils.getMappedProperty(PropertyUtils.java:564)
          at
          org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1651)
          at
          org.apache.commons.beanutils.PropertyUtilsTestCase.testGetPropertyTypeMappedPeriods(PropertyUtilsTestCase.java:1131)

          Show
          Eoin Curran added a comment - Forgot to include test case. in PropertyUtilsTestCase: /** Test setting mapped values with periods in the key. */ public void testSetMappedPeriods() throws Exception { // String value PropertyUtils.setNestedProperty(bean,"mappedProperty(key.with.a.dot)", "Special Value"); assertEquals("Can retrieve directly", "Special Value", bean.getMappedProperty("key.with.a.dot")); // Object value PropertyUtils.setNestedProperty(bean,"mappedObjects(nested.property)", new TestBean()); assertNotNull("Can retrieve directly", bean.getMappedObjects("nested.property")); } public void testGetPropertyTypeMappedPeriods() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { PropertyUtils.setNestedProperty(bean,"mappedObjects(nested.property)", new TestBean()); assertEquals(String.class,PropertyUtils.getPropertyType(bean,"mappedObjects(nested.property).stringProperty")); } produces: java.lang.IllegalArgumentException: Invalid mapped property 'mappedProperty(key' at org.apache.commons.beanutils.PropertyUtils.getMappedProperty(PropertyUtils.java:564) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1651) at org.apache.commons.beanutils.PropertyUtilsTestCase.testSetMappedPeriods(PropertyUtilsTestCase.java:1118) java.lang.IllegalArgumentException: Invalid mapped property 'mappedObjects(nested' at org.apache.commons.beanutils.PropertyUtils.getMappedProperty(PropertyUtils.java:564) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1651) at org.apache.commons.beanutils.PropertyUtilsTestCase.testGetPropertyTypeMappedPeriods(PropertyUtilsTestCase.java:1131)
          Hide
          Niall Pemberton added a comment -
              • COM-809 has been marked as a duplicate of this bug. ***
          Show
          Niall Pemberton added a comment - COM-809 has been marked as a duplicate of this bug. ***
          Hide
          Niall Pemberton added a comment -

          Eoin,

          I agree we should fix this. I have also been looking at the other PropertyUtils
          issue (see COM-882) and have a version that fixes both that issue and this
          one.

          I have run my version through the Unit tests (including an additional test for
          this issue) and it works fine. I'll attach my combined patch and also I'm going
          to do some more work on the Unit Tests to for both these bugs.

          It would be good if some of the more experienced committers (i.e. everyone
          else ) could take a look before I apply this patch.

          thanks

          Niall

          Show
          Niall Pemberton added a comment - Eoin, I agree we should fix this. I have also been looking at the other PropertyUtils issue (see COM-882 ) and have a version that fixes both that issue and this one. I have run my version through the Unit tests (including an additional test for this issue) and it works fine. I'll attach my combined patch and also I'm going to do some more work on the Unit Tests to for both these bugs. It would be good if some of the more experienced committers (i.e. everyone else ) could take a look before I apply this patch. thanks Niall
          Hide
          Niall Pemberton added a comment -

          Created an attachment (id=12067)
          Combined PropertyUtilsBean Patch for COM-1284 and COM-882

          Show
          Niall Pemberton added a comment - Created an attachment (id=12067) Combined PropertyUtilsBean Patch for COM-1284 and COM-882
          Hide
          Niall Pemberton added a comment -

          Created an attachment (id=12079)
          Updated PropertyUtilsBean Test Case for COM-1284 and COM-882

          Show
          Niall Pemberton added a comment - Created an attachment (id=12079) Updated PropertyUtilsBean Test Case for COM-1284 and COM-882
          Hide
          Niall Pemberton added a comment -

          Decision has been taken to not apply the fix for COM-882 at this point in
          time - therefore I'm going to attach a patch just for this bug for review.

          Niall

          Show
          Niall Pemberton added a comment - Decision has been taken to not apply the fix for COM-882 at this point in time - therefore I'm going to attach a patch just for this bug for review. Niall
          Hide
          Niall Pemberton added a comment -

          Created an attachment (id=12108)
          Fix to PropertyUtilsBean so that setNestedProperty and getPropertyDescriptor also handle dot notation in keys

          Show
          Niall Pemberton added a comment - Created an attachment (id=12108) Fix to PropertyUtilsBean so that setNestedProperty and getPropertyDescriptor also handle dot notation in keys
          Hide
          Niall Pemberton added a comment -

          Created an attachment (id=12109)
          Amended Test Case for handling mapped property keys which contain dot notation

          Show
          Niall Pemberton added a comment - Created an attachment (id=12109) Amended Test Case for handling mapped property keys which contain dot notation
          Hide
          Niall Pemberton added a comment -

          Part of the problem with BeanUtils was that the logic processing property names was duplciated in a number of places - and this bug is a result of inconsistency in different places. BEANUTILS-259 has abstracted this logic into a separate "Resolver" type and that has fixed this issue. I added a test case for property utils to make sure that it is fixed.

          http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/expression/package-summary.html

          Show
          Niall Pemberton added a comment - Part of the problem with BeanUtils was that the logic processing property names was duplciated in a number of places - and this bug is a result of inconsistency in different places. BEANUTILS-259 has abstracted this logic into a separate "Resolver" type and that has fixed this issue. I added a test case for property utils to make sure that it is fixed. http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/expression/package-summary.html

            People

            • Assignee:
              Unassigned
              Reporter:
              Eoin Curran
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development