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

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

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0, 3.0.0.RC1
    • Component/s: camel-properties
    • Labels:
      None
    • Estimated Complexity:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: