๐ WAYPOINT LESSON
Seam bugs
โญโญ intermediateโณ 12 min read๐ Lesson 139 of 256
Un-initialized fields, dual sources of truth, wrong-this mutations.
A repair-flavored Q2 variant: given a class that almost works, the bugs live in the seams between rows of the spec table:
- The un-initialized field. Constructor sets two of three fields; the third rides Java's default (0/null). If the spec says it starts at 1, every computation touching it is off โ and the getter-only test passes while behavior tests fail.
- The copied-not-called method. A mutator recomputes a derived value that another method ALSO recomputes differently โ two sources of truth. The spec's invariant ("count always equals list.size()") is the referee: whichever method breaks it is the bug.
- The wrong-this mutation.
void adopt(Other o) { o.x = x; }updates the parameter instead of the receiver. State flows the wrong way; the rubric's "mutates this object" behavior silently fails.
Repair discipline: write the spec table as a checklist, tick each row against the code, and fix only unticked rows. On the exam (typed) this takes ninety seconds and catches every seam bug above.