Find classes that access their own subclasses during initialization

Proprietary

Marks instantiations of, static method calls on, and static field accesses on a subclass of the enclosing class, where they happen in a static field initializer or a static initializer block and therefore run while the enclosing class is being initialized. That is a circular initialization dependency: initializing the superclass triggers initialization of the subclass, which first requires its superclass to be initialized. The JVM does not deadlock, it carries on with the superclass statics still at their default values, so the subclass observes null or zero. The symptom is a field that is mysteriously unset on first access, and which class the program touches first decides whether it happens at all. A subclass declared in the enclosing class or one of its subclasses, a class literal, a static final primitive or String constant, a lambda body, a method reference and an interface constant are not marked, and test sources are not searched.

io.moderne.staticanalysis.FindSubclassAccessDuringClassInit
mod run . --recipe=io.moderne.staticanalysis.FindSubclassAccessDuringClassInit

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.