Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-3545

MethodCallExpression doesn't validate whether the method exists for all cases

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.0
    • 2.6.0
    • camel-core
    • None

    Description

      I tried to refactor

      org.apache.camel.model.language.MethodCallExpression.java
          public Expression createExpression(CamelContext camelContext) {
              Expression answer;
      
              if (beanType != null) {            
                  instance = ObjectHelper.newInstance(beanType);
                  return new BeanExpression(instance, getMethod(), parameterType); // <--
              } else if (instance != null) {
                  return new BeanExpression(instance, getMethod(), parameterType); // <--
              } else {
                  String ref = beanName();
                  // if its a ref then check that the ref exists
                  BeanHolder holder = new RegistryBean(camelContext, ref);
                  // get the bean which will check that it exists
                  instance = holder.getBean();
                  answer = new BeanExpression(ref, getMethod(), parameterType);
              }
      
              // validate method
              validateHasMethod(camelContext, instance, getMethod(), parameterType);
      
              return answer;
          }
      

      to

      org.apache.camel.model.language.MethodCallExpression.java
          public Expression createExpression(CamelContext camelContext) {
              Expression answer;
      
              if (beanType != null) {            
                  instance = ObjectHelper.newInstance(beanType);
                  answer = new BeanExpression(instance, getMethod(), parameterType); // <--
              } else if (instance != null) {
                  answer = new BeanExpression(instance, getMethod(), parameterType); // <--
              } else {
                  String ref = beanName();
                  // if its a ref then check that the ref exists
                  BeanHolder holder = new RegistryBean(camelContext, ref);
                  // get the bean which will check that it exists
                  instance = holder.getBean();
                  answer = new BeanExpression(ref, getMethod(), parameterType);
              }
      
              // validate method
              validateHasMethod(camelContext, instance, getMethod(), parameterType);
      
              return answer;
          }
      

      so that the created BeanExpression is also validate if you provide the bean type or an instance. With this change, some tests in org.apache.camel.language.SimpleTest fails.
      I'm not sure whether the tests are faulty or if it's a bug.
      Also not sure whether this should fixed in 2.6.

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            muellerc Christian Müller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: