if (!("".equals(req_.getNonEmpData())) ||!(req_.getNonEmpData().equals(null)) )
{
itemsNonEmp= req_.getNonEmpData().split(",");
}
if ((req_.getEmpData() != null) && (!req_.getEmpData().equals("")))
{
itemsEmp=req_.getEmpData().split(",");
}
I have checked with every possible scenario for checking null or empty.
But even if the value of req_.getNonEmpData()=null,its entering the block and trying to split the empty variable..Hence Null pointer exception is being thrown...At the time of debugging,I have hardcoded the value of req_.getNonEmpData() to null,then also its entering in the block.
Any suggestion ,How to check for empty or null value in req_.getNonEmpData()
The reason it goes into the IF statement is because your logic is a little flawed. You are saying:
IF ( NOT - The element is empty OR NOT - The element is null)
The problem is that it cannot be empty and null at the same time. Think about this: when the element is null what happens when you check:
!("".equals(element))
The "".equals(element) will return false, since element is null and not empty. You negate the false to true with the bang operator (!). So when the element is indeed null, your first part of your IF statement evaluates to True, and since you use the || OR operator it will short circuit there and enter the IF statement.
On a similar note, if the return from getNonEmpData() is indeed null, then calling .equals() on it would result in a NullPointerException, and he wouldn't be getting into the IF statement.
Bookmarks