Repository navigation
Description
What is the bug?
SELECT * against an index (or alias) throws an opaque NullPointerException instead of a descriptive error when the mapping contains a field of "type": "alias" whose "path" points to a target that is not present in the flattened mapping — for example a text multi-field (field.keyword), an object/nested subfield, or a renamed/removed field.
The response is:
{
"error": {
"reason": "Invalid SQL query",
"details": "Cannot invoke \"org.opensearch.sql.opensearch.data.type.OpenSearchDataType.getExprCoreType()\" because \"type\" is null",
"type": "NullPointerException"
},
"status": 400
}This gives the user no indication that the real problem is a malformed alias field in their mapping.
How can one reproduce the bug?
- Create an index with an
alias-type field whosepathtargets a.keywordmulti-field:
PUT /repro_idx
{
"mappings": {
"properties": {
"source": { "type": "text", "fields": { "keyword": { "type": "keyword" } } },
"source_alias": { "type": "alias", "path": "source.keyword" }
}
}
}- Index a document:
POST /repro_idx/_doc?refresh=true
{ "source": "hello" }- Run a
SELECT *query via the SQL plugin:
POST /_plugins/_sql
{ "query": "SELECT * FROM repro_idx" }- See the
NullPointerExceptionabove.
Note: the same failure occurs when querying an index alias whose backing index carries such a field. A SELECT * against a different backing index that does not contain the malformed alias field succeeds, which can make this look alias-specific when it is actually a per-index mapping issue.
What is the expected behavior?
The engine should return a clear, actionable error identifying the offending alias field and its unresolvable path — for example Alias field [source_alias] refers to unresolved path [source.keyword] — so the user can correct the mapping. It should not surface an internal NullPointerException.
What is your host/environment?
- OS: Linux
- Version: reproduced on
3.7.0-SNAPSHOT(mainline). The code path is present across 2.x/3.x. - Plugins: SQL
Do you have any additional context?
Root cause is in the schema-flattening step. OpenSearchDataType.validateAliasType() passes the resolved target straight into the OpenSearchAliasType constructor without a null check:
// OpenSearchDataType.java — validateAliasType()
result.put(key, new OpenSearchAliasType(originalPath, result.get(originalPath)));result is the flattened mapping built by traverseAndFlatten, which only recurses into object/nested properties; it does not include text multi-fields (.keyword). When the alias path is not a key in result, result.get(originalPath) returns null, and the constructor immediately dereferences it:
// OpenSearchAliasType.java
public OpenSearchAliasType(String path, OpenSearchDataType type) {
super(type.getExprCoreType()); // NPE when type == null
...
}The constructor already guards the alias-to-alias and alias-to-object cases with descriptive IllegalStateExceptions, but those checks run after the super() dereference, so the unresolvable-path case falls through to the NPE. A null guard in validateAliasType (or before the super() call) that throws a descriptive error would resolve this.
Activity
[BugFix] Handle opaque NullPointerException for unresolvable alias-ty…
[BugFix] Handle opaque NullPointerException for unresolvable alias-ty…