That *should* be too small to be identified as a 'dupe'. However I don't
have much experience with VB.NET compiler IL generation. It is possible
that the generated code is larger than expected (and large enough to be
seen as a valid pattern).
1) Can you try compiling your code with /o ? and see if the defects are
still reported ?
That's the "optimize" option, not sure if the vb command line options
are identical to the c# compiler). Without /o CSC is generating much
larger (and weirder) IL code. Maybe the VB compiler is doing the same?
2) If the above did not fix the issue could you compile a small sample
for me (two times, one with /o and one without it). Just enough to have
the null check + some code that will trigger the
AvoidCodeDuplicatedInSameClassRule defects.
Next fill a bug in bugzilla.novell.com [1] and attach the files (ZIPped
or not) to the report. Please state which version of the compiler (e.g.
VS2008 or VS2010) you're using.
> Am I handling this incorrectly?
To handle the null parameters, yes. Can't say for sure if the duplicate
code is related to this (or not).
Thanks
Sebastien
p.s. I won't be able to test this myself before Feb 8th week.
No. Gendarme should be able to analyze code down to FX 1.0 (VS2002).
However you do need FX3.5 to be installed. If not then Gendarme won't
start (actually it should not even install). Since you're getting
results it means you meet the basic requirements.
Just to be clear: the only time VS2008 (or above) is required is when
you wish to compile Gendarme, from source code, yourself.
> I honestly didn't check the levels of support on it, but just wanted
> to bring that up.
>
> It's definitely possible for the VB compiler to be getting screwy.
Well each .NET compiler is a bit different. That's not an issue for most
rules but, in some cases, the generated IL can be quite weird (like CSC
is when compiled without optimization) - but it's still "legal" IL.
xMSC (mono C# compilers family) and CSC are likely the most commonly
used compilers - or at least the one I'm the most familiar with.
Maybe other people on the list can comment on other compilers ?
> I've actually had it flag a single line before as duplicate code.
> Sounds impossible, but I commented out the line and it didn't flag it,
> then un-commented it and it came back.
The rule works with "patterns" which generally correspond to a few lines
of code. Of course moving a single line can "break" the pattern and
avoid two methods to match.
> Logically it made sense to move the line to another point in the
> method and that ended up fixing it. Doubt I'll be able to recreate
> that little bug, but it might be indicative of something weird with
> the VB compiler.
>
> I hacked together a small sample that is still generating the issue
> for me. I have the two versions (one compiled with optimizations and
> one without optimizations) so I'll get to uploading them in a little
> bit. This isn't like a deal breaker for me I was just wondering if
> other people saw what I was seeing.
Thanks - this is much appreciated :-) It will allow me to investigate
the issue.
Most, except the "weirdest" cases, IL generation difference can often be
accommodated with relatively small fixes to the rule (as long as we know
about it ;-)
> I actually see a good amount of strange behavior when it comes to
> using this utility with VB.NET, and so far I've just been ignoring it
> and skipping over it. Perhaps I should post a little more of those
> things over here.
If you have time please do fill bug reports on them :-) If it helps
(saving time) it's possible to make attachments, or even the bug itself,
private to novell's employees.
Thanks!
Sebastien