$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #229

Which fix removes the bug?

String role = user.getRole(); // may be null
if (role.equals("admin")) {
    grant();
}
  1. Write "admin".equals(role)
  2. Write role.equalsIgnoreCase("admin")
  3. Write role.compareTo("admin") == 0
  4. Write role.contentEquals("admin")
Calling any method on a null role throws NullPointerException; calling equals on the literal is null-safe.
Play Problem Solving ▸