Author: spouliot
Date: 2008-01-21 18:18:19 -0500 (Mon, 21 Jan 2008)
New Revision: 93461
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/NonConstantStaticFieldsShouldNotBeVisibleRule.cs
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/ChangeLog
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am
Log:
2008-01-21 Sebastien Pouliot <[EMAIL PROTECTED]>
* NonConstantStaticFieldsShouldNotBeVisibleRule.cs: New. Rule that
warns about non-constant static fields since their access needs to be
synchronized in multithreaded applications [Andreas Noever]
* Gendarme.Rules.Concurrency.xml.in: Add new rule description.
* Makefile.am: Add rule/test to the build.
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/ChangeLog
2008-01-21 23:17:18 UTC (rev 93460)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/ChangeLog
2008-01-21 23:18:19 UTC (rev 93461)
@@ -1,3 +1,11 @@
+2008-01-21 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * NonConstantStaticFieldsShouldNotBeVisibleRule.cs: New. Rule that
+ warns about non-constant static fields since their access needs to be
+ synchronized in multithreaded applications [Andreas Noever]
+ * Gendarme.Rules.Concurrency.xml.in: Add new rule description.
+ * Makefile.am: Add rule/test to the build.
+
2008-01-12 Sebastien Pouliot <[EMAIL PROTECTED]>
* DoubleCheckingLockingRule.cs: Use new Location ctor. Delay
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
2008-01-21 23:17:18 UTC (rev 93460)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Gendarme.Rules.Concurrency.xml.in
2008-01-21 23:18:19 UTC (rev 93461)
@@ -5,6 +5,12 @@
<problem>Method '{0}' uses the unreliable double-check locking
technique.</problem>
<solution>Remove the lock check that occurs outside of the
protected region. Or see:
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html</solution>
</rule>
+ <rule Name="NonConstantStaticFieldsShouldNotBeVisibleRule"
+
Type="Gendarme.Rules.Concurrency.NonConstantStaticFieldsShouldNotBeVisibleRule,
Gendarme.Rules.Concurrency, [EMAIL PROTECTED]@, Culture=neutral,
PublicKeyToken=null"
+ Uri="" >
+ <problem>Type '{0}' has some static fields that are not
constant. They may represent problems in multithreaded applications.</problem>
+ <solution>Remove the lock check that occurs outside of the
protected region. Or see:
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html</solution>
+ </rule>
<rule Name="WriteStaticFieldFromInstanceMethodRule"
Type="Gendarme.Rules.Concurrency.WriteStaticFieldFromInstanceMethodRule,
Gendarme.Rules.Concurrency, [EMAIL PROTECTED]@, Culture=neutral,
PublicKeyToken=null"
Uri="http://www.mono-project.com/Gendarme#WriteStaticFieldFromInstanceMethodRule"
>
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am
2008-01-21 23:17:18 UTC (rev 93460)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/Makefile.am
2008-01-21 23:18:19 UTC (rev 93461)
@@ -9,7 +9,8 @@
concurrency_rules_sources_in = ../../AssemblyInfo.cs.in
concurrency_rules_generated_sources = $(concurrency_rules_sources_in:.in=)
-concurrency_rules_sources = DoubleCheckLockingRule.cs
WriteStaticFieldFromInstanceMethodRule.cs
+concurrency_rules_sources = DoubleCheckLockingRule.cs
WriteStaticFieldFromInstanceMethodRule.cs \
+ NonConstantStaticFieldsShouldNotBeVisibleRule.cs
concurrency_rules_build_sources = $(addprefix $(srcdir)/,
$(concurrency_rules_sources))
concurrency_rules_build_sources += $(concurrency_rules_generated_sources)
@@ -32,7 +33,9 @@
rm -f $(DESTDIR)$(pkglibdir)/`basename $$ASM`; \
done;
-concurrency_test_sources = DoubleCheckLockingTest.cs
WriteStaticFieldFromInstanceMethodTest.cs
+concurrency_test_sources = DoubleCheckLockingTest.cs
WriteStaticFieldFromInstanceMethodTest.cs \
+ NonConstantStaticFieldsShouldNotBeVisibleTest.cs
+
concurrency_test_build_sources = $(addprefix $(srcdir)/Test/,
$(concurrency_test_sources))
Test.Rules.Concurrency.dll: $(concurrency_rules_build_sources)
$(concurrency_rules_SCRIPTS)
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/NonConstantStaticFieldsShouldNotBeVisibleRule.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/NonConstantStaticFieldsShouldNotBeVisibleRule.cs
2008-01-21 23:17:18 UTC (rev 93460)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Concurrency/NonConstantStaticFieldsShouldNotBeVisibleRule.cs
2008-01-21 23:18:19 UTC (rev 93461)
@@ -0,0 +1,57 @@
+//
+// Gendarme.Rules.Concurrency.NonConstantStaticFieldsShouldNotBeVisibleRule
+//
+// Authors:
+// Andreas Noever <[EMAIL PROTECTED]>
+//
+// (C) 2008 Andreas Noever
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Mono.Cecil;
+using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+namespace Gendarme.Rules.Concurrency {
+
+ public class NonConstantStaticFieldsShouldNotBeVisibleRule : ITypeRule {
+
+ public MessageCollection CheckType (TypeDefinition type, Runner
runner)
+ {
+ if (type.IsInterface || type.IsEnum)
+ return runner.RuleSuccess;
+
+ MessageCollection results = null;
+ foreach (FieldDefinition field in type.Fields) {
+ if (field.IsStatic && field.IsVisible () &&
!field.IsInitOnly && !field.IsLiteral) {
+ if (results == null)
+ results = new MessageCollection
();
+ Location loc = new Location (field);
+ Message msg = new Message ("This static
field is not InitOnly (readonly). Multithreaded access to this field needs to
be syncronized.", loc, MessageType.Warning);
+ results.Add (msg);
+ }
+ }
+
+ return results;
+ }
+ }
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches