[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[commit-cp] [bugs #10908] Static method mistaken for JavaBeans getter
From: |
Robert Schuster |
Subject: |
[commit-cp] [bugs #10908] Static method mistaken for JavaBeans getter |
Date: |
Sat, 06 Nov 2004 22:27:36 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.7.3) Gecko/20040930 |
This mail is an automated notification from the bugs tracker
of the project: classpath.
/**************************************************************************/
[bugs #10908] Latest Modifications:
Changes by:
Robert Schuster <address@hidden>
'Date:
Sun 11/07/2004 at 03:21 (GMT)
What | Removed | Added
---------------------------------------------------------------------------
Status | In Process | Closed
------------------ Additional Follow-up Comments ----------------------------
provided mauve tests gnu/testlet/java/beans/Introspector/getBeanInfo
for this.
/**************************************************************************/
[bugs #10908] Full Item Snapshot:
URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=10908>
Project: classpath
Submitted by: 0
On: Thu 11/04/2004 at 15:44
Category: classpath
Severity: 5 - Average
Resolution: None
Privacy: Public
Assigned to: rschuster
Status: Closed
Platform Version: None
Summary: Static method mistaken for JavaBeans getter
Original Submission: There appears to be a problem in
gnu.java.beans.IntrospectionIncubator. In the method
addMethod(java.lang.reflect.Method), there is no check whether the method is an
instance or static method. This results in methods with the signature:
public static <Type> getXXX();
being mistaken for JavaBeans property accessors. This looks and feels wrong,
and causes concrete problems for some applications that use JavaBeans.
Follow-up Comments
------------------
-------------------------------------------------------
Date: Sun 11/07/2004 at 03:21 By: Robert Schuster <rschuster>
provided mauve tests gnu/testlet/java/beans/Introspector/getBeanInfo
for this.
-------------------------------------------------------
Date: Fri 11/05/2004 at 13:02 By: 0 <None>
Hello, and thanks for the prompt response.
Yes, I do think excluding static methods with beanish signatures is the right
thing to do; it is also more consistent with the Sun implementation of
java.beans.*.
The following code can reproduce the problem:
--8<--
import java.beans.*;
import java.util.*;
import java.io.Serializable;
class TestBeanA implements Serializable {
TestBeanA() {}
public void setObject(Object o) {}
public Object getObject() { return null; }
}
class TestBeanB extends TestBeanA {
TestBeanB() {}
public static Object getSomeStaticValue() { return null; }
}
class NameComparator implements Comparator {
public boolean equals(Object o) {
return o!=null && NameComparator.class.equals(o.getClass());
}
public int compare(Object o1,Object o2) {
if (o1 instanceof PropertyDescriptor && o2 instanceof
PropertyDescriptor) {
String o1val = ((PropertyDescriptor)o1).getName();
String o2val = ((PropertyDescriptor)o2).getName();
return o1val.compareTo(o2val);
} else throw new ClassCastException();
}
private NameComparator() {}
static final NameComparator cmp = new NameComparator();
}
public class BeanTest {
public static void main(String[] args) {
try {
PropertyDescriptor[] pda =
Introspector.getBeanInfo(TestBeanA.class).getPropertyDescriptors();
PropertyDescriptor[] pdb =
Introspector.getBeanInfo(TestBeanB.class).getPropertyDescriptors();
Collection a = new TreeSet(NameComparator.cmp),b = new
TreeSet(NameComparator.cmp);
a.addAll(Arrays.asList(pda));
b.addAll(Arrays.asList(pdb));
System.out.println((a.containsAll(b) &&
b.containsAll(a))?"OK":"Error");
} catch (IntrospectionException ie) {
ie.printStackTrace(System.out);
} catch (ClassCastException cce) {
cce.printStackTrace(System.out);
}
}
}
---8<---
This will print out "OK" on Sun's JDK 1.4.2 SE, and "Error" on a JVM using the
classpath from CVS.
I can be reached via email. My user alias is 'David.White', and the DNS MX
query string is 'chipkarte.at'. (verbose munged E-Mail address, please read
carefully)
thanks!
-------------------------------------------------------
Date: Fri 11/05/2004 at 12:39 By: Robert Schuster <rschuster>
I fixed this in the way I proposed in the last post and it looks good (=
behaves as JDK now). See classpath-patches for the patch.
I let this bug report open until I have written some mauve tests for it (or is
anyone else interested in that :) ).
-------------------------------------------------------
Date: Fri 11/05/2004 at 11:01 By: 0 <None>
Hello, and thanks for the prompt response.
Yes, I do think excluding static methods with beanish signatures is the right
thing to do; it is also more consistent with the Sun implementation of
java.beans.*.
The following code can reproduce the problem:
--8<--
import java.beans.*;
import java.util.*;
import java.io.Serializable;
class TestBeanA implements Serializable {
TestBeanA() {}
public void setObject(Object o) {}
public Object getObject() { return null; }
}
class TestBeanB extends TestBeanA {
TestBeanB() {}
public static Object getSomeStaticValue() { return null; }
}
class NameComparator implements Comparator {
public boolean equals(Object o) {
return o!=null && NameComparator.class.equals(o.getClass());
}
public int compare(Object o1,Object o2) {
if (o1 instanceof PropertyDescriptor && o2 instanceof
PropertyDescriptor) {
String o1val = ((PropertyDescriptor)o1).getName();
String o2val = ((PropertyDescriptor)o2).getName();
return o1val.compareTo(o2val);
} else throw new ClassCastException();
}
private NameComparator() {}
static final NameComparator cmp = new NameComparator();
}
public class BeanTest {
public static void main(String[] args) {
try {
PropertyDescriptor[] pda =
Introspector.getBeanInfo(TestBeanA.class).getPropertyDescriptors();
PropertyDescriptor[] pdb =
Introspector.getBeanInfo(TestBeanB.class).getPropertyDescriptors();
Collection a = new TreeSet(NameComparator.cmp),b = new
TreeSet(NameComparator.cmp);
a.addAll(Arrays.asList(pda));
b.addAll(Arrays.asList(pdb));
System.out.println((a.containsAll(b) &&
b.containsAll(a))?"OK":"Error");
} catch (IntrospectionException ie) {
ie.printStackTrace(System.out);
} catch (ClassCastException cce) {
cce.printStackTrace(System.out);
}
}
}
---8<---
This will print out "OK" on Sun's JDK 1.4.2 SE, and "Error" on a JVM using the
classpath from CVS.
I can be reached via email. My user alias is 'David.White', and the DNS MX
query string is 'chipkarte.at'. (verbose munged E-Mail address, please read
carefully)
thanks!
-------------------------------------------------------
Date: Thu 11/04/2004 at 16:43 By: Robert Schuster <rschuster>
I am on this.
Can you provide a simple test case where this bug shows up? (pseudo javacode is
ok)
Do you think its OK to just exclude static methods from being added in
IntrospectionIncubator? If so my fix would replace line:
if(Modifier.isPublic(method.getModifiers())) {
// code that really adds the method
}
with
if(Modifier.isPublic(method.getModifiers()) &&
!Modifier.isStatic(method.getModifiers())) {
// code that really adds the method
}
For detailed info, follow this link:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=10908>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/