You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Andreas Winter <an...@art-of-object.de> on 2004/05/07 17:05:38 UTC

Problems with introspection

Consider the following setup:

An abstract component class X with an abstract getter and setter for a 
property prop.

An abstract component subclass SubX which implements both the getter and 
the setter of prop.

Now if you use SubX you get the following exception:

ApplicationRuntimeException: Unable to enhance class 
de.aoo.tapestry.form.SimplePropertySelection because it implements a 
non-abstract write method for property 'value'.

The problem is caused by 
ComponentClassFactory.isImplemented(PropertyDescriptor pd) which returns 
false despite the fact that both methods are implemented in SubX (the 
exception is not thrown there).

In turn this is caused by the Introspector which answers a BeanInfo 
which mixes the abtract getter from X and the concrete setter from SubX 
in the PropertyDescription.

The code example below may help to clarify this.

I consider this as a bug in Introspector, but anyway Tapestry should 
provide a work around for this (I have rewritten Introspector and 
patched Tapestry, maybe there is a simpler solution)

- Andreas




Sample code:
---------------------------------------------
package de.aoo.test;

public abstract class Superclass {
	
	public abstract int getProp();

	public abstract void setProp(int i);
}

---------------------------------------------
package de.aoo.test;

public class Subclass extends Superclass {

	public int getProp() {
		return 0;
	}

	public void setProp(int i) {
	}
}

---------------------------------------------------------

package de.aoo.test;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

public class Introspect {

    public static void main(String[] args) {
		
	try {
		BeanInfo beanInfo = Introspector.getBeanInfo(Subclass.class);
		PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
			
		for (int i = 0; i < descriptors.length; i++) {
			PropertyDescriptor descriptor = descriptors[i];
			System.out.println(descriptor.getReadMethod());
			System.out.println(descriptor.getWriteMethod());
		}
	} catch (IntrospectionException e) {
		e.printStackTrace();
	}
    }
}