Code Room
Code reviewMediumcr-g359
Subject Inconsistent errorsLevel Mid–Senior~20 minCommon in Databases & SQL interviewsIndustries Software development, Technology

Question

Review this Java Spring controller that fetches a user.

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
@GetMapping("/users/{id}")public ResponseEntity<Map<String,Object>> getUser(@PathVariable String id) {    User u = repo.findById(id).orElse(null);    Map<String,Object> body = new HashMap<>();    if (u == null) {        body.put("error", "not found");        return ResponseEntity.ok(body);    }    body.put("id", u.getId());    body.put("name", u.getName());    return ResponseEntity.ok(body);}
Run or narrate your approach, then ask the coach.