Uploaded image for project: 'Red Hat Fuse'
  1. Red Hat Fuse
  2. ENTESB-6927

Can't pass a null value when constructing a <bean> in Blueprint XML

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major Major
    • None
    • jboss-fuse-6.3
    • Aries
    • None
    • % %

      This problem arose when trying to use <bean> to instantiate an object of class javax.naming.ldap.InitialLdapContext; but I don't think the problem is specific to that class – it will affect any Java class that needs a null value in a constructor.

      InitialLdapContext has a constructor that takes two arguments; the first is a list of properties, which must be provided, and the second an array of javax.naming.ldap.Control objects which can be null, and usually will be. So it should be possible to construct it in Blueprint like this:

      <bean id="ldapServer" class="javax.naming.ldap.InitialLdapContext" scope="prototype">
              <argument>
                  <props>
                      <prop key="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory"/>
                      <!-- etc -->    
                  </props>
              </argument>
              <argument>
                   <null/>
               </argument>
          </bean>
      

      This fails, however, because Blueprint cannot find a constructor that matches (Properties,null).

      Perhaps it is necessary to specify the exact type of the null object, so the correct constructor can be found. However, none of the following work:

       <argument type="javax.naming.ldap.Control[]" value="null" />
       <argument type="[Ljavax.naming.ldap.Control;" value="null" />
       <argument type="&#91;Ljavax.naming.ldap.Control;" value="null" />
      

      The first one produces the same result as not specifying a type at all – constructor cannot be found. The others break the XML parser, in different ways.

      It really seems that there is no way in Blueprint to use <bean> to instantiate a class that has a constructor that needs a null argument. In Spring XML we can say <constructor-arg><null/></constructor-arg>, which seems to work fine.

      The workaround for this specific problem is to specify an empty array for the Control[] argument. The LDAP implementation seems happy with that, and behaves as if null were passed. But that won't work in the general case.

              Unassigned Unassigned
              rhn-support-kboone Kevin Boone
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: