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