Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S1450: Rule should not raise an issue when methods call each other #158

Closed
fmallet opened this issue Mar 31, 2017 · 2 comments
Closed
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@fmallet
Copy link
Contributor

fmallet commented Mar 31, 2017

using System;
class C
{
    private bool f; // Compliant

    public void M1()
    {
        f = true;
        M2(); // M2 modifies "f" and the field cannot be removed
        Console.Write(f);
    }

    public void M2()
    {
        f = false;
    }
}

See RSPEC-1450 and SONARCS-676

@fmallet fmallet added the Type: False Positive Rule IS triggered when it shouldn't be. label Mar 31, 2017
@fmallet fmallet added this to the 6.0 milestone Mar 31, 2017
@p3root
Copy link

p3root commented Apr 20, 2017

I have the following situation where SonarQube puts out a warning!

public class Foo {
   private readonly int moo;

  public Foo(int moo) {
      this.moo = moo;
   }

   public too() {
     //do something with this.moo
   }
   public too2() {
     //do something with this.moo
   }
   
}

In think this is an legal case, or am I wrong?

@jccollet jccollet modified the milestones: 6.1, 6.0 Apr 20, 2017
@valhristov valhristov modified the milestones: 5.11, near-future May 5, 2017
@Evangelink Evangelink modified the milestones: 6.3, near-future Jul 13, 2017
@Evangelink Evangelink assigned Evangelink and unassigned Evangelink Jul 20, 2017
@Evangelink Evangelink modified the milestones: 6.4, 6.3 Jul 24, 2017
@Evangelink Evangelink changed the title S1450 has false positive when methods call each other Fix S1450 has false positive when methods call each other Jul 28, 2017
@Evangelink Evangelink changed the title Fix S1450 has false positive when methods call each other Fix S1450: Rule should not raise an issue when methods call each other Jul 28, 2017
@Evangelink Evangelink modified the milestones: near-future, 6.4 Jul 31, 2017
@Evangelink Evangelink removed this from the near-future milestone Oct 13, 2017
@agigleux agigleux self-assigned this May 22, 2018
@agigleux agigleux added this to the 8.0 milestone May 22, 2018
@duncanp-lseg
Copy link
Contributor

@p3root Apologies the huge delay in responding, and thanks for providing a repro.

We've recently had a sweep through some older FP issues to try to resolve them and I've had a quick look at this one. I can't get the issue to repro with the following code based on the example you provided (tweaked slightly so it compiles):

    public class Foo
    {
        private readonly int moo;

        public Foo(int moo)
        {
            this.moo = moo;
        }

        public void too()
        {
            //do something with this.moo
            Console.WriteLine(moo);
        }

        public void too2()
        {
            //do something with this.moo
            Console.WriteLine(moo);
        }
    }

Does the modified code accurately reflect your scenario?

FYI the issue does repro with the m1, m2 code snipped above (again, tweaked so that it compiles).

@agigleux agigleux modified the milestones: 8.0, 7.5 Jul 30, 2018
@valhristov valhristov assigned valhristov and unassigned agigleux Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

7 participants