- Labels: --> report on spotbugs
- Status: open --> closed-rejected
As was found by http://habrahabr.ru/company/odnoklassniki/blog/255067/ there is a possibility of a nasty deadlock with weird thread dump in case when we have places in code where we initialize child class as a static variable in its parent class. Here are two fixed bug reports with code examples, some tests and fixed code:
https://github.com/google/guava/issues/1977
https://github.com/querydsl/querydsl/issues/1237
Guava issue link says that they may have such pattern used in several places.
Quick and dirty summary of the first link:
Bug is reproducible on environments where high load hits the application just after the start and there are many threads concurring for same utility classes (more specifically, children and parents with static references from parent to child).
That is not very likely to see on the real field, but at least once it happened. It seems that debugging such deadlocks is very inconvenient (as there is no real jvm lock object assigned to static inits, threads will still be in RUNNABLE state), so having such test as a code analysis would be great to have.
As for a pattern to catch... Let's have class Parent {} and class Child extends Parent {}. Anything that instantiates Child in static fields, static init blocks of Parent should be marked as possible deadlock. Of course there could be deeper inheritance tree