4 Replies Latest reply on Aug 9, 2007 2:43 PM by Scott Stark

    PropertyInfo type creation

    Ales Justin Master

      I stumbled upon this issue when testing CallbackItems:
      The getter returns non-generic List type (ReflectClassInfoImpl), but the setter has generic parameter (ParameterizedClassInfo).

       public List getBeans()
       {
       return beans;
       }
      
       public void setBeans(List<SimpleBean> beans)
       {
       this.beans = beans;
       }
      


      When we create PropertyInfo we use getter's type (in AbstractBeanInfoFactory).
      But when I do a contextual injection / callback check, I use setter's type.

      What would be a proper fix?
      To use ParameterizedClassInfo over plain ReflectClassInfoImpl?
      Or just log a warning?

        • 1. Re: PropertyInfo type creation
          Scott Stark Master

          We should be restrictive on the type so if the setter is more specific use that. If its parameterized you have to assume somewhere SimpleBean bean = beans.get(0) is being used, and allowing a list for which this would not work would cause a CCE.

          • 2. Re: PropertyInfo type creation
            Ales Justin Master

             

            "scott.stark@jboss.org" wrote:
            We should be restrictive on the type so if the setter is more specific use that.

            Any general rules on what is more restrictive?
            Or how to write AbstractBeanInfoFactory.getPropertyType()? ;-)

            • 3. Re: PropertyInfo type creation
              Ales Justin Master

               

              "alesj" wrote:

              Or how to write AbstractBeanInfoFactory.getPropertyType()? ;-)


              Simple instructions would do ...

              • 4. Re: PropertyInfo type creation
                Scott Stark Master

                 

                "alesj" wrote:
                "scott.stark@jboss.org" wrote:
                We should be restrictive on the type so if the setter is more specific use that.

                Any general rules on what is more restrictive?
                Or how to write AbstractBeanInfoFactory.getPropertyType()? ;-)

                It has to be some compiler problem solution. It seems you have to have a type tree for the non-parameterized type and find the most derived type, and then the most derived parameterized type. For these two examples of property accessors, List would be determined for both.

                 public List getBeans()
                 {
                 return beans;
                 }
                
                 public void setBeans(Iterable<SimpleBean> beans)
                 {
                 this.beans = beans;
                 }
                


                 public Iterable<SimpleBean> getBeans()
                 {
                 return beans;
                 }
                
                 public void setBeans(List beans)
                 {
                 this.beans = beans;
                 }
                


                 public Iterable<SimpleBean> getBeans()
                 {
                 return beans;
                 }
                
                 public void setBeans(List beans)
                 {
                 this.beans = beans;
                 }
                


                It gets more complicated if a concrete type vs an interface is used though, as in this crazy example:
                 public Iterable<SimpleBean> getBeans()
                 {
                 return beans;
                 }
                
                 public void setBeans(javax.management.AttributeList beans)
                 {
                 this.beans = beans;
                 }
                

                where AttributeList is a non-parameterized List with overloaded methods for adding/setting elements of type javax.management.Attribute, a non-interface type. If SimpleBean is a class its impossible to reconcile all expected uses. Its possible if SimpleBean is an interface, but that is a crazy type graph to figure out.

                I guess the main question is how much trouble do we want to go to at this point? What does the java.beans.Introspector return for the BeanInfo.PropertyDescriptor for such examples? Does it match up these as the same property with a common type, or does it see these as the same property with different accessors, or a conflict?