Validate the command-line argument and load the poems once, before binding.
Validate the command-line argument and load the poems once, before binding.
Answer
if (args.length != 1) { System.err.println("usage: java PodServer <poems-file>"); System.exit(2); } List<Poem> poems = PoemFile.load(Path.of(args[0])); if (poems.isEmpty()) throw new IllegalStateException("no poems in " + args[0]);
Fail before the port is bound, not after a client connects. Exiting non-zero on a usage error is what lets a marker (or a shell script) tell a misuse from a crash, and the emptiness check turns a silent, useless server into a startup failure you can actually read.
Harold 4e ch9 §Using ServerSockets; ch8 §Investigating Protocols with Telnet