Erorr in 2.2.0.0

5 views
Skip to first unread message

Dave Arkley

unread,
Dec 19, 2008, 4:41:42 AM12/19/08
to Gendarme
Just discovered Gendarme and am rather impresssed!

I'm using it against .net 2.0 and 3.5 assemblies on Vista x64.

However I've spotted the following problem:

--- TOF ---

3. CheckParametersNullityInVisibleMethodsRule [hide]
Problem:
A visible method does not check its parameter(s) for null values.

Found in:
Target: HFS.Core.LinqRepository.IRepository
HFS.Core.LinqRepository.RepositoryFactory::CreateConnectedRepository
(System.Data.Linq.DataContext)
Assembly: HFS.Core.LinqRepository, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null

Severity: High Confidence: Normal
Location: context
Source: ...\RepositoryFactory.cs(≈8)


Solution:
Since the caller is unkown you should always verify all of your
parameters to protect yourself.



Error is raised for code:
if (null == context) throw new ArgumentNullException("context");


Error not raised when code is:
if (context == null) throw new ArgumentNullException("context");


--- EOF ---

Let me know if you need any more info or this is posted in wrong
place!


Dave Arkley
Senior Developer
Human Facctor Software

Sebastien Pouliot

unread,
Dec 19, 2008, 8:11:20 AM12/19/08
to gend...@googlegroups.com
Hello Dave,

On Fri, 2008-12-19 at 01:41 -0800, Dave Arkley wrote:
> Just discovered Gendarme and am rather impresssed!

Thanks from everyone :)

> I'm using it against .net 2.0 and 3.5 assemblies on Vista x64.
>
> However I've spotted the following problem:
>
> --- TOF ---
>
> 3. CheckParametersNullityInVisibleMethodsRule [hide]
> Problem:
> A visible method does not check its parameter(s) for null values.
>
> Found in:
> Target: HFS.Core.LinqRepository.IRepository
> HFS.Core.LinqRepository.RepositoryFactory::CreateConnectedRepository
> (System.Data.Linq.DataContext)
> Assembly: HFS.Core.LinqRepository, Version=1.0.0.0, Culture=neutral,
> PublicKeyToken=null
>
> Severity: High Confidence: Normal
> Location: context
> Source: ...\RepositoryFactory.cs(≈8)
>
>
> Solution:
> Since the caller is unkown you should always verify all of your
> parameters to protect yourself.
>
>
>
> Error is raised for code:
> if (null == context) throw new ArgumentNullException("context");

Ah! It's not a common pattern in Mono source code (the largest code base
that I use Gendarme against). The generated IL is likely a bit different
and not considered by the rule. I'll check this over the weekend.

> Error not raised when code is:
> if (context == null) throw new ArgumentNullException("context");
>
>
> --- EOF ---
>
> Let me know if you need any more info or this is posted in wrong
> place!

Thanks for reporting the issue (and a test case!). It's ok to report
bugs on the mailing-list, but it's a bit safer (i.e. much harder to
forget) when bugs are filled at http://bugzilla.novell.com

Sebastien

p.s. if you have a few minutes (it does not take long) there is a
survey about Gendarme in progress
http://www.surveymonkey.com/s.aspx?sm=jGWGrj0mJIYj4IfxEOGrpA_3d_3d


Sebastien Pouliot

unread,
Dec 19, 2008, 8:01:43 PM12/19/08
to Gendarme
Hello Dave,

This is fixed in SVN (HEAD). I'll do a bit more testing and, if
conclusive, will backport it to the 2-2 branch later tonight. Speaking
of 2.2 I should be making a Release Candidate over the weekend (both
binaries and Win32, more recent Linux packages are already available)
that will contain this fix (among others).

Thanks for your report!
Sebastien

p.s. To anyone curious (e.g. because they use this pattern and never
seen a false positive about it) the issue does not happen when
compiled with Mono C# compilers since they generates a different IL
pattern.

On Dec 19, 8:11 am, Sebastien Pouliot <sebastien.poul...@gmail.com>
wrote:
> forget) when bugs are filled athttp://bugzilla.novell.com

Dave Arkley

unread,
Dec 22, 2008, 6:35:23 PM12/22/08
to Gendarme


On Dec 20, 1:01 am, Sebastien Pouliot <sebastien.poul...@gmail.com>
wrote:
> Hello Dave,
>
> This is fixed in SVN (HEAD). I'll do a bit more testing and, if
> conclusive, will backport it to the 2-2 branch later tonight. Speaking
> of 2.2 I should be making a Release Candidate over the weekend (both
> binaries and Win32, more recent Linux packages are already available)
> that will contain this fix (among others).

Quick work, thanks Sebastien

> Thanks for your report!
> Sebastien

Welcome

> p.s. To anyone curious (e.g. because they use this pattern and never
> seen a false positive about it) the issue does not happen when
> compiled with Mono C# compilers since they generates a different IL
> pattern.

Nice to know.

Reply all
Reply to author
Forward
0 new messages