Search code examples
javaglassfishglassfish-3introspection

Introspector finding properties that no longer exist


I'm relying on introspection for XML processing in a Java EE 6 app I've been working on for quite a while. So far it has worked just fine. However, I had to rename a property setter name. The problem is, Introspector.getBeanInfo(Class<?>) is detecting both the old and the new setters, even after I

  • stopped using JRebel,
  • purged my Maven repository,
  • blew away GlassFish and installed a fresh one, and
  • rebuilt my web app.

Also, I ensured the introspector's cache is flushed:

public class BeanUtils {
    public static Map<String, Class> propertyTypes(Class beanType) throws Exception {
        HashMap<String, Class> propertyTypes = new HashMap<>();
        for (PropertyDescriptor descriptor : Introspector.getBeanInfo(beanType).getPropertyDescriptors()) {
            propertyTypes.put(descriptor.getName(), descriptor.getPropertyType());
        }
        return propertyTypes;
    }
    // Added this to flush the introspector
    static {
        Introspector.flushCaches();
    }
}

Here is the class I'm introspecting:

public class AdhocUnavailableTimesRequestTag
{
    public AdhocUnavailableTimeRequestTag[] getAdhocUnavailableTimes()
    {
        return adhocUnavailableTimes;
    }

    public void setUnavailableTimes(AdhocUnavailableTimeRequestTag[] adhocUnavailableTimes)
    {
        this.adhocUnavailableTimes = adhocUnavailableTimes;
    }

    private AdhocUnavailableTimeRequestTag[] adhocUnavailableTimes;
}

And calling BeanUtils.propertyTypes(AdhocUnavailableTimesRequestTag.class) returns:

"adhocUnavailableTimes" => class [LAdhocUnavailableTimeRequestTag;
"class" => java.lang.Class"
"unavailableTimes" => class [LAdhocUnavailableTimeRequestTag;

What could be causing the introspector to pick up unavailableTimes when it no longer exists? And how can I fix it?


Solution

  • It would be the name of the method setUnavailableTimes. You fix it by renaming the method to setAdhocUnavailableTimes.