csharpsquid:S1186 Methods should not be empty False positive

SonarQube * Community Edition * Version 9.4 (build 54424)
csharpsquid:S1186 Methods should not be empty

This Rule ignore “#if” prerpocesor directives.
Example:

public void JobAdded(IJobDetail jobDetail) {
#if DEBUG
    _logManager.Log(LogType.Database | LogType.File, new LogMessage {
            MessageType = LogMessageType.Info,
            CustomData = { { "JobAdded", jobDetail.JobType.Name } },
            MessageCategory = this.GetTypeName()
    });
#endif
}

It “think” that this method is empty ))

Hi,

Welcome to the community!

A build is required for C# analysis. Did that build have DEBUG enabled?

 
Ann

No. DEBUG is disabled on the environment, which is attached to SonarQube. But anyway, the method is definitely not empty. Also there are some other methods in project with opposite condition “#if !DEBUG”

вт, 28 июн. 2022 г. в 19:32, G Ann Campbell via Sonar Community <notifications@sonarcommunity.discoursemail.com>:

Hi,

That method is only non-empty when DEBUG is enabled. In a non-DEBUG build/analysis, it’s empty.

 
Ann

Hi, Ann

I Do understand how “#if” constructions work (and how it is being compiled). But I do not see some adequate solution from my side. Adding some dummy commands into the method is not a good idea. I can ignore this warning. I can even treat it as not a bug or as fixed, ect. I just wanted to help you project, point you to the real life case where you might fix something, enhance some rules and make your product better.

Thanks.

WBR, Andriy

чт, 30 июн. 2022 г. в 17:07, G Ann Campbell via Sonar Community <notifications@sonarcommunity.discoursemail.com>:

1 Like

Hello @Ivanenko_Andriy,

Thanks for raising this issue and we confirm the false positive. A PR to fix this is on the way and you can track progress here:

Best regards, Martin

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

The issue is fixed and released.