Uploaded image for project: 'EJB 3.0'
  1. EJB 3.0
  2. EJBTHREE-218

@Init methods are not properly called when more than one method with the same number of parameters

    XMLWordPrintable

Details

    • Patch
    • Resolution: Done
    • Critical
    • EJB 3.0 RC1
    • None
    • None
    • None

    Description

      When there is more than one @Init method with the same number of parameters (>=1) then it is possible that the wrong @Init method is called.
      The patch also makes the test more powerful (considering inhertance etc).

      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()[i]; Class actual = initParameterTypes[i]; 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;
      }

      Attachments

        Issue Links

          Activity

            People

              wdecoste1@redhat.com William Decoste (Inactive)
              triathlon98 Joachim Van der Auwera (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: