[ checkstyle-Bugs-3386855 ] False positive in Double checked locking

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ checkstyle-Bugs-3386855 ] False positive in Double checked locking

SourceForge.net
Bugs item #3386855, was opened at 2011-08-05 08:39
Message generated for change (Comment added) made by shiromani
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=397078&aid=3386855&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: Core Framework
Group: release 5.0
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nagendra shiromani (shiromani)
Assigned to: Oliver Burn (oburn)
Summary: False positive in Double checked locking

Initial Comment:
Checkstyle analysis using version 5.4 is reporting Double checked locking error even if we try to use volatile keyword in the code.

Please check the following pages :

http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
http://en.wikipedia.org/wiki/Double-checked_locking

The documentation in the above pages suggest that the volatile keyword is introduced to resolve this error from JDK 1.5+ versions.

But Checkstyle is reporting the error even if we use volatile keyword in the code.

Code:
 
// Works with acquire/release semantics for volatile//
class Foo {
    private volatile Helper helper = null;
    public Helper getHelper() {
        Helper result = helper;
        if (result == null) {
            synchronized(this) {
                result = helper;
                if (result == null)
                    helper = result = new Helper();
            }
        }
        return result;
    }
 
    // other functions and members...
}

Output of Checkstyle execution:

java -jar checkstyle-5.4-all.jar -c checkstyle.xml Foo.java
Starting audit...
Foo.java:10:17:
 The double-checked locking idiom is broken and should be avoided.
Audit done.

 Is it a false positive in Checkstyle reporting? Please help us in resolving this error.

Thanks and Regards,
Nagendra Shiromani



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

>Comment By: Nagendra shiromani (shiromani)
Date: 2011-11-22 08:00

Message:
Can someone please help us on this issue?

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

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

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Checkstyle-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-devel