[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: |
anonymous |
Subject: |
[commit-cp] [bugs #10908] Static method mistaken for JavaBeans getter |
Date: |
Fri, 05 Nov 2004 08:10:03 -0500 |
User-agent: |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) |
This mail is an automated notification from the bugs tracker
of the project: classpath.
/**************************************************************************/
[bugs #10908] Latest Modifications:
Changes by: Anonymous user
Date:
Fre 05.11.2004 at 08:03
------------------ Additional Follow-up Comments ----------------------------
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!
/**************************************************************************/
[bugs #10908] Full Item Snapshot:
URL: <http://savannah.gnu.org/bugs/?func=detailitem&item_id=10908>
Project: classpath
Submitted by: 0
On: Don 04.11.2004 at 10:44
Category: classpath
Severity: 5 - Average
Resolution: None
Privacy: Public
Assigned to: rschuster
Status: In Process
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: Fre 05.11.2004 at 08: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: Fre 05.11.2004 at 07: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: Fre 05.11.2004 at 06: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: Don 04.11.2004 at 11: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/