Code Room
Code reviewHard
Question
Review this Java method that reserves inventory, then charges the card, and undoes the reservation if the charge fails.
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.
Learn the concepts
public void purchase(Order o) { inventory.reserve(o.sku(), o.qty()); try { payment.charge(o.card(), o.total()); } catch (ChargeException e) { inventory.release(o.sku(), o.qty()); // compensate throw e; }}Run or narrate your approach, then ask the coach.