Hi!
I was fixing some issues gathered by SonarQube when I stumbled upon the following issue:
“SonarQube violation: Possible null pointer dereference in ___ due to return value of called method”
This error was found in the following code: ... else if (foo.list().length > 0) { ... }
I attempted to resolve this by rewriting as: ... else if (null != foo.list() && foo.list().length > 0) { ... }
foo is an instance of the File class in Java, and is directly instantiated through new File(...)
The only potential null is the return value of list(). That is why I explicitly check for this in my attempted solution.
My question is; is my solution incorrect? If not, this might be a bug.
I’m currently using SonarQube version 5.6.6.
Best Regards,
Simon Sirak