google-code-export / wro4j

Automatically exported from code.google.com/p/wro4j
1 stars 1 forks source link

Incorrect Double checked locking in ConfigurableProcessorsFactory #915

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Below code is using incorrect double checked locking pattern. 'volatile' has to 
be added for the member variables. See: 
http://stackoverflow.com/questions/7855700/why-is-volatile-used-in-this-example-
of-double-checked-locking 

Code:

  private Map<String, ResourcePreProcessor> preProcessorsMap;
  private Map<String, ResourcePostProcessor> postProcessorsMap;

  /**
   * To be used for internal usage. Ensure that returned object is not null.
   */
  private Map<String, ResourcePreProcessor> getPreProcessorsMap() {
    if (this.preProcessorsMap == null) {
      synchronized (this) {
        if (this.preProcessorsMap == null) {
          this.preProcessorsMap = newPreProcessorsMap();
        }
      }
    }
    return this.preProcessorsMap;
  }

  /**
   * To be used for internal usage. Ensure that returned object is not null.
   */
  private Map<String, ResourcePostProcessor> getPostProcessorsMap() {
    if (this.postProcessorsMap == null) {
      synchronized (this) {
        if (this.postProcessorsMap == null) {
          this.postProcessorsMap = newPostProcessorsMap();
        }
      }
    }
    return this.postProcessorsMap;
  }

Original issue reported on code.google.com by dkwak...@gmail.com on 21 Jan 2015 at 9:54

GoogleCodeExporter commented 9 years ago
Thanks for reporting it.

Original comment by alex.obj...@gmail.com on 21 Jan 2015 at 9:56