commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 28358] - [beanutils] Problems on indexed property with JDK 1.4
Date Thu, 27 Jan 2005 21:22:16 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=28358>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=28358





------- Additional Comments From niallp@apache.org  2005-01-27 22:22 -------
I've written a test case to investigate the problems described 
(IndexedPropertyTestCase which I'll attach in a minute) and there appears to be 
a few different issues I can find.

1) Difference between JDKs
==========================
I found that there is a difference in behavour of IndexedPropertyDescriptor 
with different JDK versions (I tested with JDK 1.3.1_04 and JDK 1.4.2_05 on a 
W2K machine) in respect of indexed properties that use java.util.List (rather 
than Arrays).

If you define a bean with the following "indexed" methods for a property "foo":

  public List getFoo()
  public String getFoo(int index)
  public void setFoo(List foo)
  public void setFoo(int index, String foo)

Both JDK 1.3.1_04 and JDK 1.4.2_05 will return an IndexedPropertyDescriptor for 
the "foo" property and calling the getIndexedReadMethod() and 
getIndexedWriteMethod() methods works consistently. Where the beaviour differs 
between the JDKs is in what the getReadMethod() and getWriteMethod() methods  
of IndexedPropertyDescriptor return. JDK 1.3.1_04 returns the methods you would 
expect but JDK 1.4.2_05 returns null.

So it looks to me like the only way to ensure a consistent behaviour is to use 
Arrays for indexed properties - i.e. use method signatures with the following 
kind of format:

  public Strin[] getFoo()
  public String getFoo(int index)
  public void setFoo(String[] foo)
  public void setFoo(int index, String foo)

Looking at the JavaBeans spec, it only appears to talk about arrays and not 
java.util.List in respect of indexed properties. I'm also wondering how JDK 5 
behaves?

2) IllegalArgumentException - argument type mismatch
====================================================
Wendy in her test seems to have uncovered an un-related bug in the 
BeanUtilsBean's setProperty() method. Her "things" property in the test bean 
she supplied does use Arrays and therefore IndexedPropertyDescriptor is working 
correctly whichever JDK version is in use.

The problem here is that if the PropertyDescriptor type returned is an 
IndexedPropertyDescriptor then it always uses the getIndexedPropertyType() to 
determine the type. IMO it should differentiate depending on whether you are 
trying to set the property to a whole new Array or whether you are trying to 
set just an element of the Array. If setProperty() is called with a property 
name in the format "foo[x]" then it should use the getIndexedPropertyType() to 
determine the type (which it currently does) BUT if you call setProperty() with 
a name in the format "foo" then it should use the getPropertyType() to 
determine the type.

I modfied BeanUtilsBean to do this (I'll attach a patch showing the change) and 
this resolved this issue.

3) BeanUtilsBean.getProperty() different for Lists/Arrays
=========================================================
Testing under JDK 1.3.1_04 (because 1.4.2_05 fails because of the 
IndexPropertyDescriptor problem) results in different behaviours for Arrays and 
java.util.List properties when using the BeanUtilsBean's getProperty() method. 
If the property is an Array, it returns a String containing the first element 
in the Array. If the property is a List then it returns a String containing 
comma separated list of the values. Seems strange to me that these are treated 
differently.



-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message