Commons BeanUtils
  1. Commons BeanUtils
  2. BEANUTILS-345

BeanUtilsBean.setProperty does not handle some kind of nested properties

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.1
    • Component/s: Bean / Property Utils
    • Labels:
      None
    • Environment:

      Windows XP, java 1.6

      Description

      If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

      Example

      MyBean.java
      public class MyBean {
      
      	String [][]matr =new String[][]{{"1","2"},{"3","4"}};
      	
      	public String[][] getMatr() {
      		return matr;
      	}
      	public void setMatr(String[][] matr) {
      		this.matr = matr;
      	}
      }
      

      When calling

       BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample")

      the method does not set the first element of first array.

      I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java

      BeanUtilsBean.java
      920: // Calculate the property type
      921:       if (target instanceof DynaBean) {
      922:            DynaClass dynaClass = ((DynaBean) target).getDynaClass();
      923:            DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
      924:            if (dynaProperty == null) {
      925:                return; // Skip this property setter
      926:            }
      927:            type = dynaProperty.getType();
      928:        } else if (target instanceof Map) {
      929:            type = Object.class;
      930:            // BEGIN PATCH 
      931:        } else if (target.getClass().isArray() && index>=0) {
      932:        	type = Array.get(target, index).getClass();
      933:        	// END PATCH
      934:        } else {
      ......
      ......
      

        Issue Links

          Activity

          Simone Riccucci created issue -
          Simone Riccucci made changes -
          Field Original Value New Value
          Description If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example

          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }

          When calling BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample") the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java

          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          .......
          If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example
          {code:title=MyBean.java|borderStyle=solid}
          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }
          {code}
          When calling BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample") the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java
          {code:title=borderStyle=solid}
          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          .......
          {code}
          Simone Riccucci made changes -
          Description If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example
          {code:title=MyBean.java|borderStyle=solid}
          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }
          {code}
          When calling BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample") the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java
          {code:title=borderStyle=solid}
          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          .......
          {code}
          If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example
          {code:title=MyBean.java|borderStyle=solid}
          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }
          {code}
          When calling BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample") the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java
          {code:borderStyle=solid}
          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          .......
          {code}
          Simone Riccucci made changes -
          Description If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example
          {code:title=MyBean.java|borderStyle=solid}
          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }
          {code}
          When calling BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample") the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java
          {code:borderStyle=solid}
          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          .......
          {code}
          If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example
          {code:title=MyBean.java|borderStyle=solid}
          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }
          {code}
          When calling {code:borderStyle=solid} BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample"){code} the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java
          {code:borderStyle=solid}
          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          .......
          {code}
          Simone Riccucci made changes -
          Description If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example
          {code:title=MyBean.java|borderStyle=solid}
          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }
          {code}
          When calling {code:borderStyle=solid} BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample"){code} the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java
          {code:borderStyle=solid}
          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          .......
          {code}
          If we have a Bean containing a two dimension array, the method setProperty of class BeanUtilsBean does not work correctly.

          Example
          {code:title=MyBean.java|borderStyle=solid}
          public class MyBean {

          String [][]matr =new String[][]{{"1","2"},{"3","4"}};

          public String[][] getMatr() {
          return matr;
          }
          public void setMatr(String[][] matr) {
          this.matr = matr;
          }
          }
          {code}
          When calling {code:borderStyle=solid} BeanUtilsBean.getInstance().setProperty(myBean, "matr[0][0]","Sample"){code} the method does not set the first element of first array.

          I have patched this behaviour adding the line between comment //BEGIN PATCH and //END PATCH to BeanUtilsBean.java
          {code:title=BeanUtilsBean.java|borderStyle=solid}
          920: // Calculate the property type
          921: if (target instanceof DynaBean) {
          922: DynaClass dynaClass = ((DynaBean) target).getDynaClass();
          923: DynaProperty dynaProperty = dynaClass.getDynaProperty(propName);
          924: if (dynaProperty == null) {
          925: return; // Skip this property setter
          926: }
          927: type = dynaProperty.getType();
          928: } else if (target instanceof Map) {
          929: type = Object.class;
          930: // BEGIN PATCH
          931: } else if (target.getClass().isArray() && index>=0) {
          932: type = Array.get(target, index).getClass();
          933: // END PATCH
          934: } else {
          ......
          ......
          {code}
          Hide
          Niall Pemberton added a comment -

          I agree with your suggestion - thanks for the patch, I have fixed this:

          http://svn.apache.org/viewvc?view=rev&revision=822308

          Show
          Niall Pemberton added a comment - I agree with your suggestion - thanks for the patch, I have fixed this: http://svn.apache.org/viewvc?view=rev&revision=822308
          Niall Pemberton made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Assignee Niall Pemberton [ niallp ]
          Fix Version/s 1.8.1 [ 12314024 ]
          Resolution Fixed [ 1 ]
          Niall Pemberton made changes -
          Link This issue is related to BEANUTILS-368 [ BEANUTILS-368 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          168d 2h 14m 1 Niall Pemberton 06/Oct/09 16:08

            People

            • Assignee:
              Niall Pemberton
              Reporter:
              Simone Riccucci
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development