Skip to content
Advertisement

What does “class loading deadlock” mean here?

I have this classes:

public class User {

    public static final NonRegisteredUser NON_REG_USER = new NonRegisteredUser();

    //...

    public static class NonRegisteredUser extends User {
        //...
    }

}

And code inspector is detecting this warning:

Referencing subclass NonRegisteredUser from superclass User initializer might lead to class loading deadlock

What does it mean exactly?

Advertisement

Answer

The deadlock can only occur if you have 2 threads and one starts to load User and one starts to load NonRegisteredUser. There are synchronizations in place that will cause a deadlock, but then it requires separate threads. If the loading happens in a single thread, there is no deadlock as the thread owns both locks.

Hence the might in the message. However deadlocks usually do tend to require a specific environment, so there’s nothing weird about that.

Advertisement