Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-281

MethodExecutor incorrectly tests for empty parameters list

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1
    • 3.2
    • None

    Description

      Currently MethodExecutor constructor contains code 

      if (method != null) {
          Class<?>[] formal = method.getParameterTypes();
          // if the last parameter is an array, the method is considered as vararg
          if (formal != null && MethodKey.isVarArgs(method)) {
              vastart = formal.length - 1;
              vaclass = formal[vastart].getComponentType();
          }
      }

      variable formal is never null, beacause Javadoc for getParameterTypes  states that  "returns an array of length 0 if the underlying executable takes no parameters." (implementation invokes  clone - so there always be an object)

      So test for empty parameter list  should not test for null, but for empty array - 

      if (formal.length > 0 && MethodKey.isVarArgs(method)) {

      .

      Problem is that MethodKey.isVarArgs is very costly (it traverses class hierarchy, and throws Exception for every object which does not have method by this name) - so invocation of isVarArgs should be avoided if not required. Currently it is always called due to wrong test condition

       

       

       

      Attachments

        Issue Links

          Activity

            People

              henrib Henri Biestro
              mhankus Mirek Hankus
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: