Finding potential bad assignments in thread-safe code?
Hi,
I am looking for a way to find potential issues in code that should be thread-safe. I would like to find "unauthorized" assignments in Spring beans, i.e.
public class MyBean {
private Object myAttribute;
public Object someNonSetterMethod(Object param1, Object... otherParams) {
myAttribute = param1;
// ... etc
}
public void setMyAttribute(Object o) {
myAttribute = o;
}
}
The assignment in someNonSetterMethod is obviously wrong because it modifies the internal state of a singleton, which will surely have consequences in other threads.
Now, it seems that IDEA has all the information needed to find such bugs: it knows that MyBean is a Spring bean (thanks to the Spring facet), it knows that myAttribute is a class attribute, and that someNonSetterMethod is modifying the state of this attribute via an assignment.
Would it be possible to find automatically such cases, perhaps using structural search? I tried looking at the doc but couldn't find any template capable of doing this...
Thanks
请先登录再写评论。