Noel Yap
Noel Yap

Reputation: 19798

What concurrency warnings should I expect from FindBugs?

I have the following code:

import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;

@ThreadSafe
public class Aoeu {
    @GuardedBy("this")
    private long aoeu;

    public long getAoeu() {
        return aoeu;
    }

    public void setAoeu(long aoeu) {
        this.aoeu = aoeu;
    }
}

From what I've read, FindBugs understands the JCiP annotations (indeed, 1.3.9 ships with them) but I don't get any warnings from the above code. According to, I expect to see:

IS: Field not guarded against concurrent access (IS_FIELD_NOT_GUARDED)

This field is annotated with net.jcip.annotations.GuardedBy, but can be accessed in a way that seems to violate the annotation.

Upvotes: 4

Views: 404

Answers (1)

ashish
ashish

Reputation: 11

Please check below code it shows the bug

class Test 
        {
            @net.jcip.annotations.GuardedBy("this")
            private int field;
            /**
             * 
             */
            public Test()
            {

            }

            /**
             * 
             */
            public void setField()
            {
                field++;
            }

        }

Upvotes: 1

Related Questions