Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2011-01-22 19:28:54 +0300
committerSebastien Pouliot <sebastien@ximian.com>2011-01-24 02:56:43 +0300
commit0e2a686459e1fc4acb67a9804339ebcfba2bbd86 (patch)
tree497ee474dd5e9d1614f6319000e2d795ccd87208
parent5c0881cffa0f5db7a213cc32a4aac853c0b3551b (diff)
Allow 'is' as a valid null check on parameters
* CheckParametersNullityInVisibleMethodsRule.cs: Allow 'is' as a valid null check on parameters * Test/CheckParametersNullityInVisibleMethodsTest.cs: Test case for above, provided by Iristyle
-rw-r--r--gendarme/rules/Gendarme.Rules.Correctness/CheckParametersNullityInVisibleMethodsRule.cs3
-rw-r--r--gendarme/rules/Gendarme.Rules.Correctness/Test/CheckParametersNullityInVisibleMethodsTest.cs39
2 files changed, 42 insertions, 0 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Correctness/CheckParametersNullityInVisibleMethodsRule.cs b/gendarme/rules/Gendarme.Rules.Correctness/CheckParametersNullityInVisibleMethodsRule.cs
index 6b06a731..c5e0e647 100644
--- a/gendarme/rules/Gendarme.Rules.Correctness/CheckParametersNullityInVisibleMethodsRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Correctness/CheckParametersNullityInVisibleMethodsRule.cs
@@ -157,6 +157,9 @@ namespace Gendarme.Rules.Correctness {
next = next.Next;
nc = next.OpCode.Code;
break;
+ case Code.Isinst:
+ has_null_check.Set (parameter.GetSequence ());
+ return;
}
if (null_compare.Get (nc)) {
diff --git a/gendarme/rules/Gendarme.Rules.Correctness/Test/CheckParametersNullityInVisibleMethodsTest.cs b/gendarme/rules/Gendarme.Rules.Correctness/Test/CheckParametersNullityInVisibleMethodsTest.cs
index 302c1f91..65307c4e 100644
--- a/gendarme/rules/Gendarme.Rules.Correctness/Test/CheckParametersNullityInVisibleMethodsTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Correctness/Test/CheckParametersNullityInVisibleMethodsTest.cs
@@ -755,5 +755,44 @@ namespace Tests.Rules.Correctness {
{
AssertRuleSuccess<CheckParametersNullityInVisibleMethodsTest> ("ChecksObjectAndMember");
}
+
+ // test case from Iristyle
+ // https://github.com/Iristyle/mono-tools/commit/d27c6d10ccebde1d1c3d600279fc35802581f266
+ public void ReassignsRefBeforeCheck (ref object test)
+ {
+ //uncommenting this line makes the test succeed
+ //if (null == test) { throw new ArgumentNullException("test"); }
+
+ //follow this general pattern because of FxCop false positive on CA1062
+ //http://connect.microsoft.com/VisualStudio/feedback/details/560099/ca1062-false-positive-with-byref-arguments
+ object testCopy = test;
+
+ if (null == testCopy)
+ throw new ArgumentNullException ("test");
+ test = testCopy;
+ }
+
+ [Test]
+ [Ignore ("by design the rule only checks parameter arguments, not variables, fields, return value...")]
+ public void ParameterAssignedToVariableBeforeCheck ()
+ {
+ AssertRuleSuccess<CheckParametersNullityInVisibleMethodsTest> ("ReassignsRefBeforeCheck");
+ }
+
+ // test case provided by Iristyle - bnc665193
+ // https://github.com/Iristyle/mono-tools/commit/5afbd0a3ef746ff6fdb3db4e1be53995c1734be4
+ public void ChecksIsType (Exception ex)
+ {
+ //only non-nulls may pass
+ if (ex is ArgumentException) {
+ ex.ToString ();
+ }
+ }
+
+ [Test]
+ public void AllowsIsCheck ()
+ {
+ AssertRuleSuccess<CheckParametersNullityInVisibleMethodsTest> ("ChecksIsType");
+ }
}
}