SonarQube version: 7.9.1
Language: Csharp
In the below code example, SQ raises issue S1854 (Dead stores should be removed) for line:
int exitCode = Program.BatchRunFailed;
However, if an exception is raised in the try-block (before the exitCode
is set to BatchRunSuccessful
), then the initial exitCode
will remain on BatchRunFailed
and that will be passed to SaveBatchRun
and returned. So I believe it is not a useless assignment.
public async Task<int> Start(IEndpointInstance endpointInstance, IBatchProcessor batchProcessor, BatchOptions options)
{
int exitCode = Program.BatchRunFailed; // const int with value -1
Exception exception = null;
try
{
await batchProcessor
.Proces(endpointInstance)
.ConfigureAwait(false);
Archive(options);
exitCode = Program.BatchRunSuccessful; // const int with value 0
}
catch (SystemException e)
{
exception = e;
}
SaveBatchrun(exitCode, exception);
return exitCode;
}