Today we found this template in our code:
class Foo { private List<String> errors; public void addError(String error) { ... } public List<String> getErrors(); }
While the code is running, this is a singleton Spring bean, and it is introduced in several independent places, and bean consumers assume that each of them has its own list of errors. Thus, it introduces subtle errors.
The obvious solution is to train developers to avoid such an error, but I was wondering if there is a static or temporary code analysis tool that can find such an error.
For example, the bean post processor could parse the bean before returning it and look for private fields that are not @Autowired .
source share