This discussion is archived
2 Replies Latest reply: Jun 20, 2010 4:44 PM by 843807 RSS

PropertyDescriptor.getWriteMethod occasionally returns null

843807 Newbie
Currently Being Moderated
I'm getting an odd problem where PropertyDescriptor.getWriteMethod will correctly return a method at first, but as the program runs, it starts returning null.

The class I'm using looks, in part, like this:
public class Clazz {  
private String label;  
private String name;
  public String getName() {
return name;

public void setName(String name) { = name;

public String getLabel() {
if(label == null) {
label = name;            
return label;

public void setLabel(String label) {
this.label = label;
I also have the following method:
public static void setVal(String name, Object[] vals, Object o)
            throws IntrospectionException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        Object obj = o;
        PropertyDescriptor[] propDescs = Introspector.getBeanInfo(obj.getClass()).getPropertyDescriptors();
        for(PropertyDescriptor desc : propDescs) {
            if(desc.getName().equals(name)) {
                Method m = desc.getWriteMethod();
                if(m != null) {
                    m.invoke(obj, vals);
I then call setVal("label", new Object[]{"foo"}, c) where c is an instance of Clazz. The for loop manages to find the appropriate property, so then the method executes
Method m = desc.getWriteMethod();
Under most circumstances, this will return the setLabel(String label) method. However, if I run this in the program it's located in, after several lengthy, intensive database accesses and calls, desc.getWriteMethod will start returning null for that method call. If I ignore the Introspector, and just create the method directly from the class, I can find and use the method; I just can't access it through the PropertyDescriptor. I can't reproduce this via a simple unit test, though it is reproducible in the program, though the steps to do so vary (the basic set of steps remains more or less the same; it just may require different numbers of iterations).

Does anyone know what might be causing this? The error only happens for the setLabel method; if I execute this for the name property of Clazz, it'll work consistently well.

Edited by: dragoran on Jul 30, 2009 7:42 AM

Edited by: dragoran on Jul 30, 2009 7:44 AM