I am going through a code analysis report of my project and got a lot of issues on null dereference.
We always declare a object as null. Let's say
String str = null;
Perform business logic with conditional operators
if (a.equals(b)) { s = "Assigned"; }
then assign the string to value objects.
form.setString(str);
We have followed the similar kind of coding practice everywhere in the codebase and handled not null check perfectly across the code base.
But we still getting "null dereference" security vulnerability issue. I dont think it is a valid vulnerability as we do not null check before accessing any variable from VO.
There could be a valid argument, what would happen if the busines logic does not execute and set null in your VO. But it is handled well before accessing it.
Also,
I do not have any issues in initializing a blank string (or any primitive data types) instead of null (with equivalent). This would work if I add empty check instead of not null. But, What about collections framework? If I initialize an array list and instantiate it (instead of null) , would it allocate memory for the list?
List strList = new ArrayList();
Please advise, if I can ignore these kind of null dereference issues from the report or should I handle them by instantiating it.