0

I have a query I am making a call to a method like this from another piece of code within same class

String message = "null";
//In this case have too show the Yes/No button screen
return performManualVerification(transaction, patientId, scriptInfo, message);

As seen above the message contain string null I am passing this to the below method but while debugging I was checking that it was not going for null check block it should go inside null check block it is going on No phone block. Please advise

private int performManualVerification(ITransaction transaction,
      String patientId, String scriptInfo, String message)
  {

    if (message.equalsIgnoreCase(null))
    {
      int UserResponse = messageBox.showMessage("patientinfoVerification",
          null, IMessageBox.YESNO);

      if (UserResponse == IMessageBox.YES) {
               Map<String, List<String>> ppvValidatedinfo = getValidatedPatientData(transaction, patientId, scriptInfo);
        if(ppvValidatedinfo.get(patientId) != null){

          return MANUALLY_VERIFIED; // manually verified
        }      

      } 
        return RETURN_SALE;   
    }


    messageBox.showMessage("Nophone", null, IMessageBox.OK);

    int UserResponse = messageBox.showMessage("patientinfoVerification",
        null, IMessageBox.YESNO);

    if (UserResponse == IMessageBox.YES) {

      Map<String, List<String>> ppvValidatedinfo = getValidatedPatientData(transaction, patientId, scriptInfo);
      if(ppvValidatedinfo.get(patientId) != null){

        return MANUALLY_VERIFIED; // manually verified
      }      

    } 
      return RETURN_SALE;   
  }
Amarnath
  • 8,736
  • 10
  • 54
  • 81

3 Answers3

2

String message = "null";

This is a string with value as null. But what you need is,

String message = null;

Read about What is null in Java? post and the answer written by @polygenelubricants was well explained.

And also look at this constraint, this will give you a NullPointerException if message is null.

 if (message.equalsIgnoreCase(null)) 

So first check whether it is null or not.

if(message == null) {
   // do something.
} else {
   // Do something.
}
Community
  • 1
  • 1
Amarnath
  • 8,736
  • 10
  • 54
  • 81
0

To get around this issue, you should be using "null" with quotes and not just null, which has a different meaning.

  • "null" is just another Java `String.
  • null (without quotes) is a literal which can be assigned to object references usually meaning they don't refer to any object.

On the other hand, if you just want to assign the reference a null value, you should use the null literal and not the String and you can compare it like this:

    String s = null;
    if(s == null)
Swapnil
  • 8,201
  • 4
  • 38
  • 57
0

I think you should use null in quotes for getting the expected result.

Tushar Paliwal
  • 301
  • 4
  • 11