OverviewWhen your program recursively descends a composite data structure so that occasionally more than one step down is taken via a single recursive call, you've come upon the Double Descent pattern. We discuss ClassCastExceptions and the conceptual errors behind this bug. Although usually easier to debug than other, more insidious erroneous behaviors, ClassCastExceptions are often symptoms of conceptual errors in recursively descending a composite data structure. We'll discuss where programmers should look to find this pattern of bug, how to recognize the pattern, and what to do to minimize its occurrence. Unlike the dreaded NullPointerException-which says nothing about what was expected to occur instead of the null pointer (see more in 10)-a ClassCastException is relatively easy to debug. A ClassCastException often occurs in a program that is performing a recursive descent over a data structure. I call this the Double Descent bug pattern. Here's the breakdown of this bug pattern:
|