我应该从FindBugs中得到什么并发警告?
发布时间:2020-12-15 02:29:54 所属栏目:Java 来源:网络整理
导读:我有以下代码: import net.jcip.annotations.GuardedBy;import net.jcip.annotations.ThreadSafe;@ThreadSafepublic class Aoeu { @GuardedBy("this") private long aoeu; public long getAoeu() { return aoeu; } public void setAoeu(long aoeu) { this.a
我有以下代码:
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. 解决方法
请检查下面的代码,它显示了错误
class Test { @net.jcip.annotations.GuardedBy("this") private int field; /** * */ public Test() { } /** * */ public void setField() { field++; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |