JCIP Annotations - what does Findbugs check for @GuardedBy and @ThreadSafe?

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

JCIP Annotations - what does Findbugs check for @GuardedBy and @ThreadSafe?

by DominicTulley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have recently integrated Findbugs into our build cycle and we are about to embark on the use of the JCIP annotations in our code.  Having done some reading, I found that FindBugs understands these annotations and performs checks, however it's hard to find out precisely what is checked and also if all the annotations trigger any form of checking at all.

@Immutable - checks for final fields and appears to work

@ThreadSafe - I have written a simple unsafe class and annotated as ThreadSafe but Findbugs doesn't spot it.  Further, it's not clear in the list of possible bugs from findbugs that there is anything to be reported.

@GuardedBy - I have annotated a field as GuardedBy("mutex") and provided Get/Set methods that don't synchronise.  Findbugs again doesn't seem to spot this.  For this case, there at least appears to be a problem type available that could be reported, it just doesn't get reported.

I would appreciate if someone could give me some direction - are these defects or expected behaviour? If expected, what form of fault actually triggers the bug reports?

Thanks,

-Dominic

Re: JCIP Annotations - what does Findbugs check for @GuardedBy and @ThreadSafe?

by Howard Mak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I encountered the same problem [where @GuardedBy("anything-but-this") wasn't being checked].

It appears that "@GuardedBy ... may be not fully implemented by FindBugs" according to the following link

http://sourceforge.net/tracker/?func=detail&aid=1872999&group_id=96405&atid=614696

- Howard

DominicTulley wrote:
I have recently integrated Findbugs into our build cycle and we are about to embark on the use of the JCIP annotations in our code.  Having done some reading, I found that FindBugs understands these annotations and performs checks, however it's hard to find out precisely what is checked and also if all the annotations trigger any form of checking at all.

@Immutable - checks for final fields and appears to work

@ThreadSafe - I have written a simple unsafe class and annotated as ThreadSafe but Findbugs doesn't spot it.  Further, it's not clear in the list of possible bugs from findbugs that there is anything to be reported.

@GuardedBy - I have annotated a field as GuardedBy("mutex") and provided Get/Set methods that don't synchronise.  Findbugs again doesn't seem to spot this.  For this case, there at least appears to be a problem type available that could be reported, it just doesn't get reported.

I would appreciate if someone could give me some direction - are these defects or expected behaviour? If expected, what form of fault actually triggers the bug reports?

Thanks,

-Dominic
LightInTheBox - Buy quality products at wholesale price