Code Room
Code reviewHardcr-g593
Subject Http retry idempotencyLevel Senior–Staff~22 minCommon in Networking & APIs interviewsIndustries Software development, Technology

Question

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.

Talk through your review
Code to reviewjava
PaymentResult charge(String account, long cents) {    for (int attempt = 0; attempt < 3; attempt++) {        try {            HttpResponse<String> r = client.send(                HttpRequest.newBuilder(URI.create(PAY_URL))                    .POST(BodyPublishers.ofString(body(account, cents)))                    .build(),                BodyHandlers.ofString());            return parse(r);        } catch (IOException e) {            continue;        }    }    throw new RuntimeException("charge failed");}
Run or narrate your approach, then ask the coach.