OverviewWhen code that uses recursively defined data types signals an exception and the base-case definitions are handled inconsistently by client code, there may be a Dangling Composite bug; we discuss the core of the problem, the NullPointerException. Dangling composites result from defining a recursive data type in such a way that certain base cases of the definition are not given their own classes. Instead, null pointers are inserted into the various composite data types. Instances of the data type are then used as if these null pointers were filled in properly. I call this the Dangling Composite bug pattern because the offending code is an application of the Composite design pattern that is imperfect because the composite data types contain dangling references (that is, null pointers). Here's this bug pattern in a nutshell:
|