Hey,
Thanks a lot for the precisions. Okay, so now I see the issue... And unfortunately you won't be able to do a lot about it, except probably marking the issues as false positive, for the time being.
To give you a bit more details, a few of the SonarJava rules are based on our Symbolic Execution (SE) engine (for instance S2259, S4165 or S2095). This SE engine is building method summaries (similarly to what I shown in my last message) only for methods which are non-overridable (private, or final, or static), and within the file being analyzed. For any other method, we assume we learn nothing and let the engine continue with known constraints on variable (null, non-null, true, false, etc.). We talk here of Cross-Procedural Context-Sensitive Path-Sensitive Data Flow Analysis.
Now, when a method is called from another part of the source file, the SE engine jumps to the method declaration, study the possible outcomes, and deduces constraints on parameters and return values. It then goes back to the caller, and continues with what it learns from the invocation. Implicitly, it means that the definition of the method should be available in the syntax tree to produces such summaries with an adequate precision (and lower as much as possible the FP rate).
We have been working intensively last year on extending the SE engine to be able to handle Cross-file (x-file) data flow analysis, and therefore compute method summaries when we don't have access to the code itself, but only to the bytecode. It however raises numerous questions (when do we stop following invocations? how deep are we exploring? what constraint should we keep or ignore? should we explore libraries? how to report in SQ/SL the path when code is not available? etc.) and the results we were getting from this are currently not satisfactory to be enabled in production (too many FPs for too few new relevant issues).
In your case, however, it would have solved the issue and make the FP disappear, because we would have computed correctly the method behavior, even if present in another file. It would have discarded the null-case, and discard the issue.
This feature is unfortunately not mature enough to be pushed further for the time being, and we need time to address all the questions such approach is asking.
I can not tell you when we will go back to this subject, but I created the following (way too large) ticket to cover the case you are facing:
SONARJAVA-2778
But be sure that we will come back to the topic at some point, but I can not give you a "when".
Regards,
Michael