Fix sonarqube complaints for .net application

poojasureshkumar
poojasureshkumar used Ask the Experts™
on
Hi,
Thanks!
This is regarding sonarqube complaint. I am using

public async Task<(Guid, string, Guid)> GetAllCategories()
{
    return (Guid.Parse(data["Id"].ToString()),
            data["StatusName"].ToString(),
            Guid.Parse(data["StatusId"].ToString())
    );
}

Open in new window


Sonarqube is complaining "Remove this return statement or make it conditional" . Please help me how to fix this bug..

Kind regards,
Pooja
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
you may try the following:

public async Task<(Guid, string, Guid)> GetAllCategories()
{
       Guid guidId = Guid.Parse(data["Id"].ToString()) ;
       string statusId = data["StatusName"].ToString();
       Guid guidStatusId = Guid.Parse(data["StatusId"].ToString());
       return (guidId, statusId, guidStatusId);
}

Open in new window


shouldn't make much difference but perhaps gives better error message.

Sara

Author

Commented:
Hi Sara,
I already tried that and still is giving the same report at return line.

Kind regards,
Pooja
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
How are you calling this method? What does that code look like?
Top Expert 2016

Commented:
can you try to using 3 tasks instead of one:

public async Task<Guid> GetAllCategoriesIdGuid()
{
       Guid guidId = Guid.Parse(data["Id"].ToString()) ;
       return guidId;
}

public async Task<string> GetAllCategoriesStatusName()
{
       string statusId = data["StatusName"].ToString();
       return statusId;
}

public async Task<Guid> GetAllCategoriesStatusIdGuid()
{
       Guid guidStatusId = Guid.Parse(data["StatusId"].ToString());
       return guidStatusId;
}

Open in new window


Sara
my bad! calling unconditional  return , so the sonarqube warns that  control will not  moved to other statements. Thanks for the help guys!

Kind regards,
Pooja

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial