Skip to content

Fixes a NullReferenceException bug when the ValueSetValidator is null#16379

Merged
Matthew-Wise merged 1 commit intoumbraco:contribfrom
Shazwazza:patch-2
Jun 1, 2024
Merged

Fixes a NullReferenceException bug when the ValueSetValidator is null#16379
Matthew-Wise merged 1 commit intoumbraco:contribfrom
Shazwazza:patch-2

Conversation

@Shazwazza
Copy link
Copy Markdown
Contributor

Fixes a bug where the ValueSetValidator is null which will cause a NullReferenceException.

Prerequisites

  • I have added steps to test this contribution in the description below

Description

When creating a custom index based on Umbraco content/media via this code:

services.AddExamineLuceneIndex<UmbracoContentIndex, ConfigurationEnabledDirectoryFactory>("TestIndex");

It will mean that this index's LuceneDirectoryIndexOptions.ValueSetValidator will be null and when rebuilding the index, a null reference exception will occur.

To resolve this, it is required that an explicit value set validator is applied to the options, like:

public class LuceneEditorialIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
    private readonly IUmbracoIndexConfig _umbracoIndexConfig;

    public LuceneEditorialIndexOptions(IUmbracoIndexConfig umbracoIndexConfig)
    {
        _umbracoIndexConfig = umbracoIndexConfig;
    }

    public void Configure(string? name, LuceneDirectoryIndexOptions options)
    {
        if (name?.Equals("EditorialIndex") is false)
        {
            return;
        }

        options.Validator = _umbracoIndexConfig.GetContentValueSetValidator();
    }

    // not used
    public void Configure(LuceneDirectoryIndexOptions options) => throw new NotImplementedException();
}

However, it is not clear that this is a requirement but either way, a null reference exception shouldn't be thrown.

A reference: SDKits/ExamineX#103 (comment)

…llReferenceException.

Fixes a bug where the ValueSetValidator is null which will cause a NullReferenceException.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 23, 2024

Hi there @Shazwazza, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@georgebid
Copy link
Copy Markdown
Contributor

Hey @Shazwazza! Thanks a lot for your PR, someone on the core collaborators team will review this soon 😸

@Matthew-Wise Matthew-Wise merged commit f9a6712 into umbraco:contrib Jun 1, 2024
@Matthew-Wise
Copy link
Copy Markdown
Contributor

Hi @Shazwazza

Confirmed working and what a sneaky bug, from a user point of view it all works but you can see the null ref in the logs.

Thanks
Matt

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants