nullPointer envoked on .contains method when querying for String jobTitle

58 views Asked by At

I'm writing a return statement for specific role provisioning -

If everything is in scope, it should return as true and assign the role.

Part of the logic requires the user of

identity.getAttribute("jobTitle")**.contains("Nurse");**

For example, here are 3 lines of the Java assignment logic-

return "ACTIVE".equalsIgnoreCase(identity.getAttribute("status")
 && !"attributeString1".equalsIgnoreCase(identity.getAttribute("company")) 
 && !"attributeString2".equalsIgnoreCase(identity.getAttribute("jobTitle"))
 && identity.getAttribute("jobTitle").contains("Nurse");

When I run a system wide refresh on all of the Identity cubes in our environment, the .contains method will invoke "Attempt to invoke method contains on null value BSF info: RuleTest at line: 0 column: columnNo" which I can only assume is it's finding an Identity Cube with a null jobTitle and erroring out.

My question for you guys: is there a way I can add a null check for jobTitle without breaking my logic?

probably not correct at all - but I tried to input an if statement right after the && like following:

&& if(identity.getAttribute("jobTitle") != null)
 {   identity.getAttribute("jobTitle").contains("Nurse");     }

but that led to a parsing error and never looked right.

Thank you for any help you can provide!

1

There are 1 answers

0
devatherock On

You can add the null check to the existing condition before the contains check. You would also need to add the missing closing parenthesis after the first condition. The complete return statement might end up looking something like below:

return "ACTIVE".equalsIgnoreCase(identity.getAttribute("status"))
   && !"attributeString1".equalsIgnoreCase(identity.getAttribute("company")) 
   && !"attributeString2".equalsIgnoreCase(identity.getAttribute("jobTitle"))
   && identity.getAttribute("jobTitle") != null
   && identity.getAttribute("jobTitle").contains("Nurse");