Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TableState.SortLabel initialized to null #7629

Closed
1 of 2 tasks
th3oth3rjak3 opened this issue Oct 10, 2023 · 2 comments · Fixed by #8926
Closed
1 of 2 tasks

TableState.SortLabel initialized to null #7629

th3oth3rjak3 opened this issue Oct 10, 2023 · 2 comments · Fixed by #8926

Comments

@th3oth3rjak3
Copy link

Bug type

Component

Component name

MudTable / TableState

What happened?

While creating a URL query parameter using the TableState.SortLabel property, I got a NullReferenceException even though the SortLabel type is declared as "string" instead of "string?".

Current Definition:

public class TableState
    {
        public int Page { get; set; }

        public int PageSize { get; set; }

        public string SortLabel { get; set; }

        public SortDirection SortDirection { get; set; }
    }

Expected Definition 1

public class TableState
    {
        public int Page { get; set; }

        public int PageSize { get; set; }

        public string SortLabel { get; set; } = string.Empty;

        public SortDirection SortDirection { get; set; }
    }

Expected Definition 2

public class TableState
    {
        public int Page { get; set; }

        public int PageSize { get; set; }

        public string? SortLabel { get; set; }

        public SortDirection SortDirection { get; set; }
    }

Expected behavior

Since the property is defined as "string" I would expect it to be initialized to an empty string. Alternatively, the definition could be changed to indicate a possible null value "string?".

Reproduction link

https://try.mudblazor.com/why

Reproduction steps

  1. Write a function that expects a non-null string.
  2. Construct a new table with TableState
  3. Pass the TableState.SortLabel property to your function
  4. SortLabel is null even though it should be "string"
    ...

Relevant log output

No response

Version (bug)

6.9.0

Version (working)

No response

What browsers are you seeing the problem on?

Firefox, Chrome, Microsoft Edge

On what operating system are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ScarletKuro
Copy link
Member

While creating a URL query parameter using the TableState.SortLabel property, I got a NullReferenceException even though the SortLabel type is declared as "string" instead of "string?".

As you can see from this issue #6535 Table component is not yet annotated with nullable, therefore this rule doesn't apply here.

@ScarletKuro
Copy link
Member

Hi.
This has been done for v7 in this PR #8926
The SortLabel is marked as string?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants