我有以下代码:
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 理解 JCiP 注释(实际上,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.
最佳答案
请检查下面的代码它显示了错误
class Test
{
@net.jcip.annotations.GuardedBy("this")
private int field;
/**
*
*/
public Test()
{
}
/**
*
*/
public void setField()
{
field++;
}
}
关于concurrency - 我应该从 FindBugs 中得到什么并发警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8479599/