Bug 621968

Summary: Gendarme - ArgumentOutOfRangeException from AvoidCodeDuplicatedInSameClassRule, NullReferenceException from EnsureLocalDisposalRule
Product: [Mono] Mono: Tools Reporter: Eric Zeitler <eric.zeitler>
Component: GendarmeAssignee: Sebastien Pouliot <spouliot>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Major    
Priority: P5 - None    
Version: 2.6.x   
Target Milestone: ---   
Hardware: x86   
OS: Windows XP   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: zipped Debug directory for repro case
zipped Debug directory for repro case 2
zipped Debug directory for repro case 2

Description Eric Zeitler 2010-07-13 17:22:16 UTC
Created attachment 375658 [details]
zipped Debug directory for repro case

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.458.1 Safari/534.3

Rule:	Gendarme.Rules.Smells.AvoidCodeDuplicatedInSameClassRule

Target:	System.IO.Packaging.PackUriHelperInternal

Stack trace: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32 index)
   at Mono.Cecil.Cil.VariableDefinitionCollection.get_Item(Int32 index)
   at Gendarme.Rules.Smells.InstructionMatcher.AreEquivalent(Instruction source, Instruction target)
   at Gendarme.Rules.Smells.InstructionMatcher.Match(Pattern pattern, InstructionCollection target)
   at Gendarme.Rules.Smells.CodeDuplicatedLocator.GetDuplicatedCode(MethodDefinition current, MethodDefinition target)
   at Gendarme.Rules.Smells.CodeDuplicatedLocator.CompareMethodAgainstTypeMethods(MethodDefinition current, TypeDefinition targetType)
   at Gendarme.Rules.Smells.AvoidCodeDuplicatedInSameClassRule.CheckType(TypeDefinition type)
   at Gendarme.Framework.Runner.OnType(RunnerEventArgs e)
   at Gendarme.GuiRunner.OnType(RunnerEventArgs e)
   at Gendarme.Framework.Runner.Run()
   at Gendarme.GuiRunner.Execute()Rule:	Gendarme.Rules.Correctness.EnsureLocalDisposalRule

Target:	T OpenTK.Graphics.TextureRegion2D`1::get_Item(System.Int32,System.Int32)

Stack trace: System.NullReferenceException: Object reference not set to an instance of an object.
   at Mono.Cecil.MethodReference.Resolve()
   at Gendarme.Rules.Correctness.EnsureLocalDisposalRule.DoesReturnDisposable(MethodReference call)
   at Gendarme.Rules.Correctness.EnsureLocalDisposalRule.CheckMethod(MethodDefinition method)
   at Gendarme.Framework.Runner.OnMethod(RunnerEventArgs e)
   at Gendarme.Framework.Runner.Run()
   at Gendarme.GuiRunner.Execute()

Reproducible: Always

Steps to Reproduce:
1. Add the attached DLLs to be analyzed using No Limit/High/High/All Code.
Actual Results:  
Report generated, but error message occured.

Expected Results:  
Should have not encountered any errors.
Comment 1 Eric Zeitler 2010-07-13 17:31:37 UTC
Created attachment 375660 [details]
zipped Debug directory for repro case 2
Comment 2 Eric Zeitler 2010-07-13 17:33:33 UTC
Created attachment 375663 [details]
zipped Debug directory for repro case 2

oops, wrong zip
Comment 3 Sebastien Pouliot 2010-07-14 01:47:55 UTC
It looks like both issues are fixed on trunk (what will be released as 2.8) using both the console and the wizard runners. 

[mono] ~/svn/mono-tools/gendarme/testcases/621968 @ mono --debug ../../bin/gendarme.exe --config ../../rules/rules.xml --set self-test --log regress.log *.dll
Gendarme v2.7.0.0
Copyright (C) 2005-2010 Novell, Inc. and contributors

Initialization: 1.7 seconds
Annotations.dll: 0.5 seconds
Framework4Bridge.dll: 8.7 seconds
Microsoft.Contracts.dll: <0.1 seconds
OpenTK.Contracts.dll: 36.3 seconds
OpenTK.dll: 82.2 seconds
TearDown: <0.1 seconds

5 assemblies processed in 129.5 seconds.
108128 defects found. Report written to: `regress.log'.


You can try the latest 2.7 preview (from the google group) if you want to make sure about the issues. I'll re-build 2.6 later to see if I can duplicate them (to confirm the fix and close the bug).

Thanks for your report.
Comment 4 Eric Zeitler 2010-07-14 23:06:06 UTC
(In reply to comment #3)
> You can try the latest 2.7 preview (from the google group) if you want to make
> sure about the issues. I'll re-build 2.6 later to see if I can duplicate them
> (to confirm the fix and close the bug).

It seems that Google Groups are (still?) having some problems with files/pages and they suggest using Google Sites in the meantime.  Is it possible to upload the preview there?
Comment 5 Sebastien Pouliot 2010-07-15 00:50:21 UTC
again?!? sigh, where's the world going if we can't trust google with data on their site ? ;-)

I'll publish a new preview (that includes the fix for #622007) and upload it somewhere else - watch the Google group discussion for the exact location. Thanks for letting me know about it!
Comment 6 Eric Zeitler 2010-07-19 20:11:59 UTC
I downloaded/compile trunk and I can confirm that both issues are fixed, though another shows up.  Will file a separate bug.
Comment 7 Sebastien Pouliot 2010-08-04 16:57:34 UTC
closing (fix confirmed in comment #6)