In my experience the pattern is this:
- System works, often for years
- An error is reported
- The developer investigates the error and finds a bit of code which seems to be completely flawed and declares that it "could never have worked"
- The bug gets fixed and the legend of the code that could never have worked (but did for years) grows
Let's be logical here. Code that could never have worked... could never have worked. If it did work then the statement is false.
So I'm going to say that a bug exactly as described (that is observing the flawed code stops it working) is patently nonsense.
In reality what has happened is one of two things:
1) The developer hasn't fully understood the code. In this case the code is usually a mess and somewhere in it has a major but non-obvious sensitivity to some external condition (say a specific OS version or configuration that governs how some function works in some minor but significant way). This external condition is altered (say by a server upgrade or change which is believed to be unrelated) and in doing so causes the code to break.
The developer then looks at the code and, not understanding the historical context or having the time to trace through every possible dependency and scenario, declared that it could never have worked and rewrites it.
In this situation, the thing to understand here is that the idea that "it could never have worked" is provably false (because it did).
That's not to say rewriting it is a bad thing - it's often not, while it's nice to know exactly what was wrong often that's time consuming and rewriting the section of code is often faster and allows you to be sure that you've fixed things.
2) Actually it never worked, just no-one has ever noticed. This is surprisingly common, particularly in large systems. In this instance someone new starts and starts looking at things in a way no-one did before, or a business process changes bringing some previously minor edge case into the main process, and something which never really worked (or worked some but not all of the time) is found and reported.
The developer looks at it and declares "it could never have worked" but the users say "nonsense, we've been using it for years" and they're sort of right but something they consider irrelevant (and usually fail to mention until the developer finds the exact condition at which point they go "oh yes, we do do that now and didn't before") has changed.
Here the developer is right - it could never have worked and didn't ever work.
But in either case one of two things is true:
- The claim "it could never have worked" is true and it never has worked - people just thought it did
- It did work and the statement "it could never have worked" is false and down to a (usually reasonable) lack of understanding of the code and its dependencies