Skip to content

Bug Fix: Fix text structure NPE when fields have null value #125922

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

Merged
merged 6 commits into from
Apr 29, 2025

Conversation

weizijun
Copy link
Contributor

when fields have null value, Elasticsearch will return NPE.
I add a check to avoid it.

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.1.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Mar 31, 2025
@weizijun weizijun changed the title [BUG] Fix text structure NPE when fields have null value Bug Fix: Fix text structure NPE when fields have null value Mar 31, 2025
@mayya-sharipova mayya-sharipova added :ml Machine learning and removed needs:triage Requires assignment of a team area label labels Mar 31, 2025
@elasticsearchmachine elasticsearchmachine added the Team:ML Meta label for the ML team label Mar 31, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

@davidkyle davidkyle self-assigned this Apr 10, 2025
@davidkyle davidkyle added auto-backport Automatically create backport pull requests when merged v8.19.0 >bug labels Apr 10, 2025
Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weizijun please do you have a stack trace for the NPE?

null values are filtered out here, I can't see a code path where fieldValues could contain a null.

@@ -425,7 +425,10 @@ static Tuple<Map<String, String>, FieldStats> guessMappingAndCalculateFieldStats
);
}

Collection<String> fieldValuesAsStrings = fieldValues.stream().map(Object::toString).collect(Collectors.toList());
Collection<String> fieldValuesAsStrings = fieldValues.stream()
.filter(value -> value != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.filter(value -> value != null)
.filter(Objects::nonNull)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@weizijun
Copy link
Contributor Author

please do you have a stack trace for the NPE?

Here is a example:
put the file test.json to the kibana upload file page:

{"field":["a", "b", null]}
{"field":["a", "b", null]}
{"field":["a", "b", null]}
{"field":["a", "b", null]}
{"field":["a", "b", null]}
{"field":["a", "b", null]}
{"field":["a", "b", null]}
{"field":["a", "b", null]}

it will see the error:

[null_pointer_exception Root causes: null_pointer_exception: null]: null

Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for adding the test case and the example for reproducing the error.

null values are filtered out here, I can't see a code path where fieldValues could contain a null.

I understand now the null check is in the list not the contents of the list and that was causing the problem. Thanks for the fix.

@davidkyle davidkyle enabled auto-merge (squash) April 28, 2025 10:21
@davidkyle
Copy link
Member

@elasticmachine test this please

@davidkyle
Copy link
Member

@elasticmachine test this please

@davidkyle davidkyle merged commit dbedc51 into elastic:main Apr 29, 2025
17 of 18 checks passed
davidkyle pushed a commit to davidkyle/elasticsearch that referenced this pull request Apr 29, 2025
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.18
8.19
9.0
8.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >bug external-contributor Pull request authored by a developer outside the Elasticsearch team :ml Machine learning Team:ML Meta label for the ML team v8.17.6 v8.18.1 v8.19.0 v9.0.1 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants