S2259 false positive

24 views
Skip to first unread message

patrick...@bertelsmann.de

unread,
Sep 1, 2016, 2:39:03 AM9/1/16
to SonarLint
The assignment to URL inside the brackets is flagged as S2259 - possible null ref exception.

var course = this.catalogManager.GetCourseIfExists(courseNr); // Returns (Course) null if not found


if (course == null)

{

  course = new Course { MaterialNumber = courseNr};

  course.Url = "some URL";

  this.courseRepository.Add(course);

}


duarte.meneses

unread,
Sep 2, 2016, 3:41:47 AM9/2/16
to SonarLint, patrick...@bertelsmann.de
Hi,

I assume that you are using SonarLint for Visual Studio.
What version are you using?

Tamas Vajk

unread,
Sep 5, 2016, 3:54:30 AM9/5/16
to duarte.meneses, SonarLint, patrick...@bertelsmann.de
Hello Patrick,

I tried to repro your issue, but couldn't. I received you second e-mail from @Duarte, but that didn't help me either to get closer to what you're experiencing.
Could you dig a bit more into this issue? Some thoughts on this rule, which might be helpful. This rule works on an individual method bases, which means that it doesn't go into the GetCourseIfExists method. It tracks == null, != null comparisons, null and not-null assignments.

Also, you might want to give a try to the version 1.17 NuGet package, there were some improvements there.

Regards,
Tamas


Tamas VAJK | SonarSource
Language Team

--
You received this message because you are subscribed to the Google Groups "SonarLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarlint+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarlint/9a27b8d1-b919-4123-88dd-bd8ac6f83c20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages