[ checkstyle-Bugs-2843447 ] Double Checked Locking partially gives false positive

View: New views
1 Messages — Rating Filter:   Alert me  

[ checkstyle-Bugs-2843447 ] Double Checked Locking partially gives false positive

by SourceForge.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bugs item #2843447, was opened at 2009-08-24 11:38
Message generated for change (Tracker Item Submitted) made by elewis
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=397078&aid=2843447&group_id=29721

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Eric Lewis (elewis)
Assigned to: Nobody/Anonymous (nobody)
Summary: Double Checked Locking partially gives false positive

Initial Comment:
Under some circumstances (beginning with Java 5), double checked locking using volatile is in fact allowed and works.

The following code for instance works:

  /**
   * The rules in a hashed set, which is created in a lazy way.
   */
  private volatile Set<Rule> hashedRules;

  /**
   * Gets this as a {@link Set}.
   * @return the rules in a hashed set
   */
  @Nonnull
  public Set<Rule> asSet() {
    Set<Rule> hashed = this.hashedRules;
    if (hashed == null) {
      synchronized (this) {
        hashed = this.hashedRules;
        if (hashed == null) {
          hashed = ImmutableSet.copyOf(this.rules);
          this.hashedRules = hashed;
        }
      }
    }
    return hashed;
  }


See http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html

Checkstyle 5 reports this as error.

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=397078&aid=2843447&group_id=29721

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Checkstyle-devel mailing list
Checkstyle-devel@...
https://lists.sourceforge.net/lists/listinfo/checkstyle-devel