Code RoomConnection not reused
MediumPrep Room Coding #2223

Connection not reused

Code reviewNetworking & APIsMid–Senior~20 min

Review this Java client that calls a downstream service in a loop.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1String fetch(String id) throws Exception {
2 URL url = new URL("https://svc.internal/items/" + id);
3 HttpURLConnection c = (HttpURLConnection) url.openConnection();
4 c.setRequestMethod("GET");
5 try (InputStream in = c.getInputStream()) {
6 return new String(in.readAllBytes(), StandardCharsets.UTF_8);
7 } finally {
8 c.disconnect();
9 }
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.