Wow—great catch! Issues like that are maddening precisely because everything looks perfectly normal on the surface. Silent failures are the worst, and Java’s Scanner can definitely be sneaky when it comes to encoding problems.
Your explanation about the bad character being read into the buffer before the cursor reaches it makes total sense in hindsight, but it’s the kind of behavior you’d never expect unless you’ve already spent hours debugging it. The fact that it just stops as if the file ended—no error, no warning—is brutal.
Specifying the encoding is a solid workaround, but you’re right: if the data might be noisy or mixed-encoding, Scanner becomes a risky tool. A custom BufferedReader setup or even using java.nio with a CharsetDecoder (which can be configured to report malformed input) might be safer for anything nontrivial.
Still—kudos to you for tracking it down. That kind of bug feels like wrestling a ghost in the machine. 👻💻 - Visit: www.salinascaliforniafoundationrepaircontractors.com