我应该从FindBugs中得到什么并发警告?

时间:2011-12-12 19:19:14

标签: concurrency static-analysis findbugs

我有以下代码:

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;
    }
}

从我读过的内容来看,FindBugs理解JCi​​P注释(事实上,1.3.9附带了它们),但我没有从上面的代码中得到任何警告。根据,我希望看到:

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.

1 个答案:

答案 0 :(得分:1)

请查看下面显示错误的代码

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

            }

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

        }
相关问题