You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2004/02/13 05:10:49 UTC
DO NOT REPLY [Bug 26904] New: -
(g|s)etSimpleProperty fails when passing a Map
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26904>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26904
(g|s)etSimpleProperty fails when passing a Map
Summary: (g|s)etSimpleProperty fails when passing a Map
Product: Commons
Version: Nightly Builds
Platform: All
OS/Version: Other
Status: NEW
Severity: Normal
Priority: Other
Component: Bean Utilities
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: senen_de_diego@hotmail.com
I have already posted it in commons-dev@jakarta.apache.org, but maybe
this is a better place. I don't know...
In PropertyUtilsBean, calling
getNestedProperty(bean, "simpleProperty")
with bean instanceof Map works, but
getSimpleProperty(bean, "simpleProperty")
throws a NoSuchMethodException, which doesn't seem logical.
I think than Map instances should be handled in g|setSimpleProperty
instean of in g|setNestedProperty.
This is a patch which passes the tests:
Index: org/apache/commons/beanutils/PropertyUtilsBean.java
===================================================================
RCS file: /home/cvspublic/jakarta-
commons/beanutils/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java,v
retrieving revision 1.13
diff -u -r1.13 PropertyUtilsBean.java
--- org/apache/commons/beanutils/PropertyUtilsBean.java 13 Oct 2003 14:12:08 -
0000 1.13
+++ org/apache/commons/beanutils/PropertyUtilsBean.java 11 Feb 2004 17:26:21 -
0000
@@ -699,9 +699,7 @@
String next = name.substring(0, indexOfNESTED_DELIM);
indexOfINDEXED_DELIM = next.indexOf(PropertyUtils.INDEXED_DELIM);
indexOfMAPPED_DELIM = next.indexOf(PropertyUtils.MAPPED_DELIM);
- if (bean instanceof Map) {
- bean = ((Map) bean).get(next);
- } else if (indexOfMAPPED_DELIM >= 0) {
+ if (indexOfMAPPED_DELIM >= 0) {
bean = getMappedProperty(bean, next);
} else if (indexOfINDEXED_DELIM >= 0) {
bean = getIndexedProperty(bean, next);
@@ -1162,7 +1160,10 @@
PropertyDescriptor descriptor =
getPropertyDescriptor(bean, name);
if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
+ if (bean instanceof Map)
+ return ((Map) bean).get(name);
+ else
+ throw new NoSuchMethodException("Unknown property '" +
name + "'");
}
Method readMethod = getReadMethod(descriptor);
@@ -1652,9 +1653,7 @@
String next = name.substring(0, delim);
indexOfINDEXED_DELIM = next.indexOf(PropertyUtils.INDEXED_DELIM);
indexOfMAPPED_DELIM = next.indexOf(PropertyUtils.MAPPED_DELIM);
- if (bean instanceof Map) {
- bean = ((Map) bean).get(next);
- } else if (indexOfMAPPED_DELIM >= 0) {
+ if (indexOfMAPPED_DELIM >= 0) {
bean = getMappedProperty(bean, next);
} else if (indexOfINDEXED_DELIM >= 0) {
bean = getIndexedProperty(bean, next);
@@ -1672,18 +1671,7 @@
indexOfINDEXED_DELIM = name.indexOf(PropertyUtils.INDEXED_DELIM);
indexOfMAPPED_DELIM = name.indexOf(PropertyUtils.MAPPED_DELIM);
- if (bean instanceof Map) {
- // check to see if the class has a standard property
- PropertyDescriptor descriptor =
- getPropertyDescriptor(bean, name);
- if (descriptor == null) {
- // no - then put the value into the map
- ((Map) bean).put(name, value);
- } else {
- // yes - use that instead
- setSimpleProperty(bean, name, value);
- }
- } else if (indexOfMAPPED_DELIM >= 0) {
+ if (indexOfMAPPED_DELIM >= 0) {
setMappedProperty(bean, name, value);
} else if (indexOfINDEXED_DELIM >= 0) {
setIndexedProperty(bean, name, value);
@@ -1781,7 +1769,13 @@
PropertyDescriptor descriptor =
getPropertyDescriptor(bean, name);
if (descriptor == null) {
- throw new NoSuchMethodException("Unknown property '" +
+ // Handle Map instances
+ if (bean instanceof Map){
+ ((Map) bean).put(name, value);
+ return;
+ }
+ else
+ throw new NoSuchMethodException("Unknown property '" +
name + "'");
}
Method writeMethod = getWriteMethod(descriptor);
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org