-
What language is this for? Java
-
Which rule? S3516
-
Why do you believe it’s a false-positive/false-negative? The code smells detects that the two returns are null why they are not. It seems to be linked to the try{} block. This might be related to https://sonarsource.atlassian.net/browse/SONARJAVA-3063.
-
I am using SonarCloud.
-
How can we reproduce the problem? In the following code snippet, the two returns are detected as null by Sonar.
private CompletableFuture<SensitivityAnalysisResult> runSensitivityAnalysisAsync(SensitivityAnalysisRunContext context,
SensitivityAnalysis.Runner sensitivityAnalysisRunner,
Reporter reporter,
UUID resultUuid) {
lockRunAndCancelSensitivityAnalysis.lock();
try {
if (resultUuid != null && cancelComputationRequests.get(resultUuid) != null) {
return null; // 1st return
}
SensitivityAnalysisParameters sensitivityAnalysisParameters = buildParameters(context);
Network network = getNetwork(context.getNetworkUuid(), context.getOtherNetworkUuids(), context.getVariantId());
sensitivityAnalysisInputBuilderService.build(context, network, reporter);
CompletableFuture<SensitivityAnalysisResult> future = sensitivityAnalysisRunner.runAsync(
network,
context.getVariantId() != null ? context.getVariantId() : VariantManagerConstants.INITIAL_VARIANT_ID,
context.getSensitivityAnalysisInputs().getFactors(),
new ArrayList<>(context.getSensitivityAnalysisInputs().getContingencies()),
context.getSensitivityAnalysisInputs().getVariablesSets(),
sensitivityAnalysisParameters,
LocalComputationManager.getDefault(),
reporter);
if (resultUuid != null) {
futures.put(resultUuid, future);
}
return future; // 2nd return
} finally {
lockRunAndCancelSensitivityAnalysis.unlock();
}
}
The issue can also be found here: https://sonarcloud.io/project/issues?resolutions=FALSE-POSITIVE&types=CODE_SMELL&pullRequest=35&id=org.gridsuite%3Asensitivity-analysis-server&open=AYq3lYMlcV6nnVrJRNk_