2 Replies Latest reply on Feb 28, 2006 11:26 AM by kabirkhan

    Overloaded constructor confusion

    kabirkhan

      I am going through the "jca" and "rars" tests, and have run into some problems.

      The rars JBossMQUnitTestCase.xml reads:

       ...
       <bean name="GCF" class="org.jboss.mq.GenericConnectionFactory">
       ...
       </bean>
       ...
       <bean name="ConnectionFactory" class="org.jboss.mq.SpyConnectionFactory">
       <constructor>
       <parameter/></parameter>
       </constructor>
       </bean>
       ...
      


      When run, we get this error:
      844 ERROR [AbstractKernelController] Error installing to Instantiated: name=ConnectionFactory state=Described
      java.lang.IllegalArgumentException: Wrong arguments. new for target java.lang.reflect.Constructor expected=[java.util.Properties] actual=[org.jboss.mq.GenericConnectionFactory]
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.handleErrors(ReflectionUtils.java:224)
       at org.jboss.reflect.plugins.introspection.ReflectionUtils.newInstance(ReflectionUtils.java:140)
       at org.jboss.reflect.plugins.introspection.ReflectConstructorInfoImpl.newInstance(ReflectConstructorInfoImpl.java:103)
      


      It is trying to use the SpyConnectionFactory taking a java.util.Properties as it's parameter while passing in a GenericConnectionFactory. It works fine if I explicitly make it use the other constructor.

       <bean name="ConnectionFactory" class="org.jboss.mq.SpyConnectionFactory">
       <constructor>
       <parameter class="org.jboss.mq.GenericConnectionFactory"><inject bean="GCF"/></parameter>
       </constructor>
       </bean>
      


      Shouldn't the mc be able to figure out which overloaded constructor to use from the type of the injected parameter?

      A similar issue exists for QueueConnectionFactory for the JMSUnitTestCase.

        • 1. Re: Overloaded constructor confusion

          Yes it could, there are already feature requests to make this more intuitive.

          The default behaviour is geared towards string values
          where it needs to know which constructor you want to use to convert strings
          into the parameter type.

          <bean name="ConnectionFactory" class="org.jboss.mq.SpyConnectionFactory">
           <constructor>
           <parameter class="java.util.Properties">foo=bar</parameter>
           </constructor>
           </bean>
          


          • 2. Re: Overloaded constructor confusion
            kabirkhan

            OK, so I will update the tests to expicitly choose the constructor to use