if(obj == null && obj.isValid())
I'd have approximately 960 dollars per project.
if(obj == null && obj.isValid())
I'd have approximately 960 dollars per project.
Why would you encounter this (often)? It seems to me that this code would never evaluate to true.
> if (obj != null && obj.isValid()) { }
Which is semantically correct due to the fail-fast evaluate of AND, it does require a double check since it's strange from a logic point of view. This is one the reasons that brace languages are hard to optimize since you can't commute things that ought to commute.
If the two checks were independent (pure functions), it's not difficult for a compiler to determine that given enough program visibility.
This check is obviously erroneous, and found via SCA. I was saying "if I had a dollar for every time I found this [via SCA] I'd have a lot of money."
Why do you think you are encountering this particular mistake so often? Is it something about your projects, your organization, your colleagues, or Java itself?