Charge retried without idempotency
Review this Java method that retries a payment charge on failure.
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 22 min
Mark a line and say what kind of problem it is.0 findings
1PaymentResult charge(String account, long cents) {
2 for (int attempt = 0; attempt < 3; attempt++) {
3 try {
4 HttpResponse<String> r = client.send(
5 HttpRequest.newBuilder(URI.create(PAY_URL))
6 .POST(BodyPublishers.ofString(body(account, cents)))
7 .build(),
8 BodyHandlers.ofString());
9 return parse(r);
10 } catch (IOException e) {
11 continue;
12 }
13 }
14 throw new RuntimeException("charge failed");
15}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.