Skip to content

TextContainer GetLocation Throws Exception Occasionally  #396

@guyacosta

Description

@guyacosta

Describe the bug
On occasion there the RulesEngine throws an exception for certain files when trying to determine match locations from the TextContainer.cs file indicated. The issue appears to be a conditional that allows there to be an uneven number of items between the LineEnds and LineStarts lists culminating in a failure in the GetLocation method on line 218. The solution appears to be correcting the boundary limit in the constructor to include '<=' on line 35.

To Reproduce
Source code to reproduce will vary...was primarily python if that helps.
The behavior interestingly was seen while using the NuGet model but not the commandLine one -not sure why but time is limited to investigate but it is also not consistent for reasons unknown i.e. sometimes it doesn't throw an exception.

Expected behavior
Complete analysis for source without throwing an exception

Code Section
File: ..\ApplicationInspector-main\RulesEngine\TextContainer.cs
Class & Method: TextContainer : TextContainer
Line: 35

while (pos > -1)
{
           **if (pos > 0 && pos + 1 < FullContent.Length)**
           {
                    LineStarts.Add(pos + 1);
           }
           pos = FullContent.IndexOf('\n', pos + 1);
     
           if (LineEnds.Count < LineStarts.Count)
           {
                LineEnds.Add(FullContent.Length - 1);
           }
}

and in method GetLocation line 218 where the indexing exception gets thrown

result.Column = index - LineStarts[i];

Screenshots
appinsbug-txtcontainer

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions