2 Replies Latest reply on Jul 15, 2005 9:01 PM by bill.burke

    Problem when several @Init methods

    triathlon98

      It seems the code in org.jboss.ejb3.stateful.StatefulContainer.invokeInit just picks the first method annotaed with @Init, cithout looking at the parameter types. This causes InvocationException to be thrown when there are two or more @Init methods. When one of these methods has no parameters, then that one will always succeed, the other one maybe).

      Joachim

        • 1. Re: Problem when several @Init methods
          triathlon98

          Posting a reply to my own question again, the assesment above was somewhat incorrect. However, as patch in ejb3 module, org.jboss.ejb3.stateful, the code for the method getInitParameters should be replaced with

           protected Object[] getInitParameters(Method method, Class[] initParameterTypes, Object[] initParameterValues)
           {
           if (method.getParameterTypes().length == initParameterTypes.length)
           {
           for (int i = 0; i < initParameterTypes.length; ++i)
           {
           Class formal = method.getParameterTypes();
           Class actual = initParameterTypes;
           if (!isMethodInvocationConvertible(formal,actual==null?null:actual))
           return null;
           }
           return initParameterValues;
           }
           return null;
           }
          
           /**
           * Determines whether a type represented by a class object is
           * convertible to another type represented by a class object using a
           * method invocation conversion, treating object types of primitive
           * types as if they were primitive types (that is, a Boolean actual
           * parameter type matches boolean primitive formal type). This behavior
           * is because this method is used to determine applicable methods for
           * an actual parameter list, and primitive types are represented by
           * their object duals in reflective method calls.
           *
           * @param formal the formal parameter type to which the actual
           * parameter type should be convertible
           * @param actual the actual parameter type.
           * @return true if either formal type is assignable from actual type,
           * or formal is a primitive type and actual is its corresponding object
           * type or an object type of a primitive type that can be converted to
           * the formal type.
           */
           private static boolean isMethodInvocationConvertible(Class formal, Class actual)
           {
           /*
           * if it's a null, it means the arg was null
           */
           if (actual == null && !formal.isPrimitive())
           {
           return true;
           }
          
           /*
           * Check for identity or widening reference conversion
           */
           if (actual != null && formal.isAssignableFrom(actual))
           {
           return true;
           }
          
           /*
           * Check for boxing with widening primitive conversion. Note that
           * actual parameters are never primitives.
           */
          
           if (formal.isPrimitive())
           {
           if(formal == Boolean.TYPE && actual == Boolean.class)
           return true;
           if(formal == Character.TYPE && actual == Character.class)
           return true;
           if(formal == Byte.TYPE && actual == Byte.class)
           return true;
           if(formal == Short.TYPE &&
           (actual == Short.class || actual == Byte.class))
           return true;
           if(formal == Integer.TYPE &&
           (actual == Integer.class || actual == Short.class ||
           actual == Byte.class))
           return true;
           if(formal == Long.TYPE &&
           (actual == Long.class || actual == Integer.class ||
           actual == Short.class || actual == Byte.class))
           return true;
           if(formal == Float.TYPE &&
           (actual == Float.class || actual == Long.class ||
           actual == Integer.class || actual == Short.class ||
           actual == Byte.class))
           return true;
           if(formal == Double.TYPE &&
           (actual == Double.class || actual == Float.class ||
           actual == Long.class || actual == Integer.class ||
           actual == Short.class || actual == Byte.class))
           return true;
           }
           return false;
           }
          
          
          


          Posted as patch EJBTHREE-218

          Kind regards,
          Joachim

          • 2. Re: Problem when several @Init methods
            bill.burke

            Thank you!