Java test: Equals

Last modified by Sergiu Dumitriu on 2018/10/10 17:05

Question: Are there any potential issues with the following code?

String status = getStatus();
if (status.equals("stopped")) {
 // some code
}
if ("stopped".equals(status)) {
 // some code
}
  1. First if statement might throw NullPointerException
  2. The condition from second if statement is always true
  3. Second if statement might throw NullPointerException
  4. Code does not compile reporting incompatible types in first if statement