[Mono-bugs] [Bug 385666] New: TraceImp.Indent() & TraceImp.Unindent() do not update the private TraceImp.indentLevel field

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu May 1 13:07:33 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=385666


           Summary: TraceImp.Indent() & TraceImp.Unindent() do not update
                    the private TraceImp.indentLevel field
           Product: Mono: Class Libraries
           Version: 1.2.5
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: Minor
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: russell.davies at blakemere.ca
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


*************
Problem: 

TraceImp.IndentLevel does not track the actual indent level following
TraceImp.Indent() or TraceImp.Unindent(). 

Since Trace and Debug both share TraceImp, then this issue probably also
extends to Debug too, although I haven't checked. 


*************
Example:

The following C# code (targeted to NET_2.0) run on Windows, and fails on Linux. 
<C#>
int origIndentLevel = Trace.IndentLevel;
Trace.Indent();
Assert.AreNotEqual(origIndentLevel, Trace.IndentLevel);
</C#>

Mode detailed examination of Windows behaviour shows that the value reported by
Trace.IndentLevel increments and decrements in proportion to calls to
Trace.Indent() and Trace.Unindent().


*************
Analysis:
Reviewing mcs/classes/System/Syste.Diagnostics/TraceImpl.cs, the the get side
of IndentLevel property is coded as:

<C#>
  public static int IndentLevel {
      get {return indentLevel;}
      ...
   }
</C#>

However, the Indent() method is coded as:
<C#>
  public static void Indent ()
  {
     lock (ListenersSyncRoot) {
         foreach (TraceListener listener in Listeners) {
            listener.IndentLevel++;
          }
     }
  }
<\C#>

Clearly, the Indent method does not update the local indentLevel field. 
Likewise for the Unundent() method.   


*************
Proposed solution:

Perhaps all that is required is to make the Indent() and Unindent() methods
increment and decrement the local indentLevel field.  For example, the Indent()
method might be changed as follows:

<C#>
  public static void Indent ()
  {
     lock (ListenersSyncRoot) {

         // NEW CODE STARTS HERE
         indentLevel ++; 
         // END OF NEW CODE

         foreach (TraceListener listener in Listeners) {
            listener.IndentLevel++;
          }
     }
  }
<\C#>


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list