Skip to content

[DotNet] GherkinLine throws NullReferenceException when GetLineText is called on default valueΒ #374

Open
@Code-Grump

Description

@Code-Grump

πŸ‘“ What did you see?

The following exception is thrown:

Message: 
    System.NullReferenceException : Object reference not set to an instance of an object.

Stack Trace: 
    GherkinLine.GetLineText(Int32 indentToRemove)
    Token.GetTokenValue()
    ...

βœ… What did you expect to see?

Either:

  • A suitable default value such as an empty string or null.
  • An exception that indicates it's not valid to call GetLineText(...)

πŸ“¦ Which tool/library version are you using?

.NET 8 with Gherkin 32.0.0

πŸ”¬ How could we reproduce it?

The following snippet demonstrates the problem:

default(GherkinLine).GetLineText(0);

πŸ“š Any additional context?

It looks like a recent change switched GherkinLine from a class to a struct: cf4160f#diff-150d7921f11609b895fc571d0916916563d77bc54d723e6086890c2efb626e34

Structures in C# are stack-initialized and therefore should be valid without a constructor being called - i.e. it should be possible to identify an instance is the default value and handle it appropriately, both as an external caller and in the internal implementation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions