Skip to content

PR #3769 issue #3819

@jbooth88

Description

@jbooth88

Bug explanation

PR #3769 was intended to fix a null reference exception with the text box line count behavior. For some reason the PR didn't fix the problem in my app, so I cloned the repository and ran my project in debug mode. This is what I found:

In TextBoxLineCountBehavior.cs, I expected the null reference exception to occur on line 17, but the exception was actually thrown on line 18. Is this method is not thread safe? I am not sure what's going on here.

private void UpdateAttachedProperties()
{
    if (AssociatedObject != null)
    {
        AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, AssociatedObject.LineCount); //ok
        AssociatedObject.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, AssociatedObject.LineCount > 1); //NullReferenceException!
    }
}

On my local copy of the repository I changed the method body to the following, and my app stopped crashing. Should I submit a PR for this? I think what I did was a band-aid fix, and doesn't actually solve the original issue.

private void UpdateAttachedProperties()
{
    if (AssociatedObject is { } obj)
    {
        obj.SetCurrentValue(TextFieldAssist.TextBoxLineCountProperty, obj.LineCount);
        obj.SetCurrentValue(TextFieldAssist.TextBoxIsMultiLineProperty, obj.LineCount > 1);
    }
}

Version

5.2.2-ci914 pre-release

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions