Others have pointed out that the way to avoid this error is to use:
! ("".equals(mapData.get("CON_PTY_PARTY_ID")))
But no one has pointed out why this matters. The reason the literal should be on the left side of the equals comparison is to avoid the possibility of an exception if the string being compared to it is null.
As written in the question, if the value of mapData.get("CON_PTY_PARTY_ID")
was null
, then the expression would be trying to invoke the equals(..)
method of an object that doesn't exist. That would throw an exception. By putting the literal on the left, then even if the value of mapData.get("CON_PTY_PARTY_ID")
was null
, the method "".equals(...)
would be defined and would not throw an exception. It would simply return false
.