Skip to content

NET-3640 Fix S3400 FP: Don't report function with conditional compilation body #9804

Description

@tkouba

Description

On multi-platform or multi-target code, sometimes need to return constant on some platforms/targets.

Reproducer

        public static bool IsGooglePlayServicesAvailable()
        {
#if ANDROID
            try
            {
                var context = Android.App.Application.Context;
                var result = Android.Gms.Common.GoogleApiAvailability.Instance
                    .IsGooglePlayServicesAvailable(context);

                return result == Android.Gms.Common.ConnectionResult.Success;
            }
            catch
            {
                return false;
            }
#else
            // iOS / Windows platform fallback 
            return false;
#endif
        }

Product and Version

VisualStudio: 17.14.29, SonarQube ide 9.9.0.16495

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    False PositiveRule IS triggered when it shouldn't be.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions