[False-positive] java:S3516 in try{} block

  • 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) {
        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(
                context.getVariantId() != null ? context.getVariantId() : VariantManagerConstants.INITIAL_VARIANT_ID,
                new ArrayList<>(context.getSensitivityAnalysisInputs().getContingencies()),
            if (resultUuid != null) {
                futures.put(resultUuid, future);
            return future; // 2nd return
        } finally {

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_

1 Like

Hello @antoinebhs ,

Thanks for your report. Indeed, this looks like a false positive and you have also already found the corresponding ticket. I have added your report to the ticket, so that we have it for reference when we get to this issue.

Until then and should this rule create too much noise, you can consider disabling it in the quality profile.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.