Skip to content

[BUG] SELECT * throws opaque NullPointerException when an alias-type field has an unresolvable path #5535

Closed

Description

@RyanL1997

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?

  1. Create an index with an alias-type field whose path targets a .keyword multi-field:
PUT /repro_idx
{
  "mappings": {
    "properties": {
      "source": { "type": "text", "fields": { "keyword": { "type": "keyword" } } },
      "source_alias": { "type": "alias", "path": "source.keyword" }
    }
  }
}
  1. Index a document:
POST /repro_idx/_doc?refresh=true
{ "source": "hello" }
  1. Run a SELECT * query via the SQL plugin:
POST /_plugins/_sql
{ "query": "SELECT * FROM repro_idx" }
  1. See the NullPointerException above.

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

  1. added
    bug
    on Jun 10, 2026
  2. self-assigned this
    on Jun 10, 2026
  3. added a commit that references this issue on Jun 10, 2026
    30af8b2
  4. added a commit that references this issue on Jul 21, 2026
    d96fd77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

SQLbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions