Added synchronization to avoid race condition
@@ -44,7 +44,7 @@ public class SpringEnvironmentProperties {
private static final Logger log = LoggerFactory.getLogger(SpringEnvironmentProperties.class);
- private Map<String, Object> properties = new HashMap<>();
+ private volatile Map<String, Object> properties = new HashMap<>();
private Map<String, Map<String, Object>> propertiesStartingWith = new HashMap<>();
@Autowired
@@ -104,6 +104,8 @@ public class SpringEnvironmentProperties {
* get All properties
*/
public Map<String, Object> getAllProperties() {
+ if (properties == null || properties.isEmpty()) {
+ synchronized (SpringEnvironmentProperties.class) {
if (properties == null || properties.isEmpty()) {
Map<String, Object> map = new HashMap();
for (Iterator it = ((AbstractEnvironment) env).getPropertySources().iterator(); it.hasNext(); ) {
@@ -120,6 +122,8 @@ public class SpringEnvironmentProperties {
properties = decryptedMap;
}
+ }
+ }
return properties;
}
