OverviewWhen you get a NullPointerException and you suspect that class-definition constructors don't take enough arguments to initialize all the class's fields, you may be looking at the Run-On Initializer pattern. We discuss initializing all constructor fields with special classes and including multiple constructors. For various reasons, mostly bad, you will often see class definitions in which the class constructors don't take enough arguments to properly initialize all the fields of the class. Such constructors require client classes to initialize instances in several steps (setting the values of the uninitialized fields) rather than with a single constructor call. Initializing an instance in this way is an error-prone process that I refer to as a Run-On Initialization. The types of bugs that result from this process have similar symptoms and remedies, so we can group them together into the Run-On Initializer bug pattern. Here is this pattern in a nutshell:
|