Problem
Client's constructor calls three helpers that each return boolean, and discards all three results:
public Client(String host, int port) {
hostName = host;
portNumber = port;
initializeSocket();
initializeReader();
initializeWriter();
}
When initializeSocket() fails, socket stays null. initializeReader() and initializeWriter() then hit checkIfSocketIsNull(), print Socket is null., and return false — which is also discarded. Construction therefore "succeeds" with out and in both null, and the first call to sendStringToServer dereferences out.
Evidence
Read from src/SimpleServer/client/Client.java:
- lines 19-25 — the constructor, with all three return values unused
- lines 32-34 —
sendStringToServer calls out.println(s) with no null guard
- lines 49-57, 59-70, 72-83 — the three
initialize* helpers, each returning boolean
- lines 85-91 —
checkIfSocketIsNull
The consequence described above (a NullPointerException on first send) is UNVERIFIED — no compile or run was performed in the session that filed this issue. The claim follows from out being null at that call site, which is source-verifiable; the thrown exception itself was not observed.
Proposed change
The constructor should honour the results it is already being given, and the object should report or refuse rather than proceeding half-constructed. The existing helper shape (private, boolean-returning, printing on failure) is the established pattern in this codebase and should be kept — only what the constructor does with the result needs to change.
Related: ClientApp hardcodes a hostname that resolves on one machine, which is the most likely way to reach this path. See the separate issue on that.
This issue was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
drafted by Claude on behalf of Daniel Stephenson
Problem
Client's constructor calls three helpers that each returnboolean, and discards all three results:When
initializeSocket()fails,socketstaysnull.initializeReader()andinitializeWriter()then hitcheckIfSocketIsNull(), printSocket is null., and returnfalse— which is also discarded. Construction therefore "succeeds" withoutandinbothnull, and the first call tosendStringToServerdereferencesout.Evidence
Read from
src/SimpleServer/client/Client.java:sendStringToServercallsout.println(s)with no null guardinitialize*helpers, each returningbooleancheckIfSocketIsNullThe consequence described above (a
NullPointerExceptionon first send) is UNVERIFIED — no compile or run was performed in the session that filed this issue. The claim follows fromoutbeingnullat that call site, which is source-verifiable; the thrown exception itself was not observed.Proposed change
The constructor should honour the results it is already being given, and the object should report or refuse rather than proceeding half-constructed. The existing helper shape (private,
boolean-returning, printing on failure) is the established pattern in this codebase and should be kept — only what the constructor does with the result needs to change.Related:
ClientApphardcodes a hostname that resolves on one machine, which is the most likely way to reach this path. See the separate issue on that.This issue was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
drafted by Claude on behalf of Daniel Stephenson