JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
A method call from an inner class is ambiguous.
This checker identifies problems related to the definition of inner classes. Namely, inner classes can be defined in C# as static or non-static. The former cannot directly access instance fields of the outer class, while the latter have the ability to refer to the instance of the outer class passed at time of their creation and consequently also to its instance fields. However, this comes at the price of embedding an implicit reference, in each instance of the inner class, to the wrapping instance of the outer class, which makes objects larger and prevents garbage collection of the outer instance. This can result in memory exhaustion. Moreover, non-static inner classes expose the risk of ambiguity for method calls that could refer to both local methods and methods of the outer class.
| Class Name | Ambiguous Call from Inner Class (C#) | |||
|---|---|---|---|---|
| Significance | reliability | |||
| Mnemonic | CSHARP.CLASS.ACIC | |||
| Categories |
|
|||
| Availability | Available for C# only. |
|||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Ambiguous Call from Inner Class (C#)" |
namespace DocumentationExamples
{
public class InnerClasses
{
public static void Main(string[] args)
{ }
public virtual void Foo() { }
public class InnerClassesC1
{
public void Foo() { }
public void Test()
{
Foo(); // "Ambiguous Call from Inner Class (C#)" warning issued here
// - this ambiguity might be a risk to code correctness.
}
}
}
}
The programmer should for instance rewrite InnerClassesC1 as follows.
public class InnerClassesC1
{
public void Moo() { }
public void Test()
{
Moo();
}
}
Check if inner classes can be made static, consequently saving memory and reducing the burden on the garbage collector. Avoid using synonyms for methods in the inner class and in the outer class.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.