Investigate: "Referencing subclass from superclass initializer might lead to class loading deadlock" #194
Labels
investigation
Something that needs to be investigated before implementation can proceed
Milestone
According to IntelliJ, referencing a subclass from a superclass initializer might "lead to class loading deadlock". This is referring to eight classes using Immutables which contain
public static final
fields in theabstract
class which instantiate instances of the (immutable) subclass. For example, inDeleteOptions
:IntelliJ gives the following warning:
Obviously this code has been around for quite a while, since the original
consul-client
library started in 2014. So, it is most likely not causing any issues for anyone, or else someone probably would have found it by now.Here is a good discussion on SO: Referencing subclass in static variable
It is slightly different than the situation here, since the subclass is private. But the question is whether to simply suppress the IntelliJ warnings, or heed them and find a (hopefully better) way to design this to avoid the situation.
ImmutableDeleteOptions
is code generated by Immutables, so the field declaration cannot go there (unless there is something in Immutables I don't know about, which is always a possibility).But assuming it can't be put in
ImmutableDeleteOptions
, then where should these fields be created and initialized? It seems annoying to create another parallel set of classes simply to hold one (or in a few cases, two) constant fields, e.g. aDeleteOptionsConstants
class containing two fields,BLANK
andRECURSE
. It also seems annoying to even create oneConstants
class with various fields that would need to be prefixed, e.g.BLANK_DELETE_OPTIONS
,BLANK_EVENT_OPTIONS
, and so on.If I can "prove" that the current design will never cause "class loading deadlock" then I'd rather leave them where they are. But, how to prove that?
The text was updated successfully, but these errors were encountered: