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

camel-properties: get[Inital|Override]Properties should never return null

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0.RC1, 3.0.0
    • camel-properties
    • None
    • Unknown

    Description

      The properties component allow to set initial and override properties but as the methods to access such properties can return null, used may end up writing things like:

      @Override
          public void addProperties(Properties properties) {
              PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
              Properties props = pc.getInitialProperties();
      
              if (props == null) {
                  props = new Properties();
      
                  pc.setInitialProperties(props);
              } else {
                  props.putAll(properties);
              }
          }
      
          @Override
          public void addProperty(String key, Object value) {
              PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class);
              Properties props = pc.getInitialProperties();
      
              if (props == null) {
                  props = new Properties();
                  props.put(key, value);
      
                  pc.setInitialProperties(props);
              } else {
                  props.put(key, value);
              }
          }
      

      We can implement such lazy initialization logic in the component property itself.

      Attachments

        Activity

          People

            lb Luca Burgazzoli
            lb Luca Burgazzoli
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: