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

Using DefautMessage() and GenericFileMessage() without CamelContext throw Exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Bug
    • 2.20.0, 2.20.1, 2.20.2, 2.21.0
    • None
    • camel-core
    • None
    • Unknown

    Description

      Hello,

      I am using version 2.19.2 and try to migrate to version 2.20.2 (and then to 2.21.0).

      Using DefautMessage() and GenericFileMessage() without CamelContext throw Exception :

      java.lang.IllegalArgumentException: CamelContext must be specified on: Message[] at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:342)
      

      In version 2.20.0, I see that these constructor was deprecated and new contructors was introduced for this new feature https://issues.apache.org/jira/browse/CAMEL-11149 :

      To remain better backward compatibility, i would suggest to refer the new constructor in deprecated contructor  :

       @Deprecated
          public DefaultMessage() {
              this(new DefaultCamelContext()); //use new contructor with DefaultCamelContext to avoid exception
          }
      
          public DefaultMessage(CamelContext camelContext) {
              setCamelContext(camelContext);
          }
      
      
          @Deprecated
          public GenericFileMessage() {
              this(new DefaultCamelContext()); //use new contructor with DefaultCamelContext to avoid exception
          }
      
          public GenericFileMessage(CamelContext camelContext) {
              super(camelContext);
          }
      
          /**
           * @deprecated use {@link #GenericFileMessage(CamelContext, GenericFile)}
           */
          @Deprecated
          public GenericFileMessage(GenericFile<T> file) {
              this(new DefaultCamelContext(), file); //use new contructor with DefaultCamelContext to avoid exception
          }
      
          public GenericFileMessage(CamelContext camelContext, GenericFile<T> file) {
              super(camelContext);
              this.file = file;
          }
      

      Otherwise, the deprecated constructeur must be deleted in order to detect errors at compile time and not at runtime.

      Farès

      Attachments

        Activity

          People

            davsclaus Claus Ibsen
            fhassak Farès Hassak
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: