Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
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.