Skip to content

Fix NPE when creating a match-all composable index template without an inline template - #22421

Open
llilyy wants to merge 5 commits into
opensearch-project:mainfrom
llilyy:fix/global-template-npe-without-template
Open

Fix NPE when creating a match-all composable index template without an inline template#22421
llilyy wants to merge 5 commits into
opensearch-project:mainfrom
llilyy:fix/global-template-npe-without-template

Conversation

@llilyy

@llilyy llilyy commented Jul 9, 2026

Copy link
Copy Markdown

Description

Fixes a NullPointerException when creating a composable index template with a match-all pattern (*) in index_patterns and without an inline template block:

PUT /_index_template/my-catch-all
{
  "index_patterns": ["*"],
  "priority": 0,
  "composed_of": ["my-defaults"]
}
{
  "error": {
    "type": "null_pointer_exception",
    "reason": "Cannot invoke \"org.opensearch.cluster.metadata.Template.settings()\" because the return value of \"org.opensearch.cluster.metadata.ComposableIndexTemplate.template()\" is null"
  },
  "status": 500
}

Request#validate() checked the index.hidden restriction for global templates by calling indexTemplate.template().settings() without null checks. Since the template block is optional, both template() and its settings() can be null, which caused the NPE. With this change, the index.hidden validation only runs when an inline template with settings is actually present, so a match-all, composed_of-only template can be created.

The same bug existed in Elasticsearch and was fixed in 7.10.3 (elastic/elasticsearch#67310).

Added unit tests covering a global template without an inline template and one with an inline template but null settings.

Related Issues

Resolves #22420

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@llilyy
llilyy requested a review from a team as a code owner July 9, 2026 02:05
@github-actions github-actions Bot added bug Something isn't working Cluster Manager labels Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit c579dbd)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit c9b04de

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

✅ Gradle check result for c9b04de: SUCCESS

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.42%. Comparing base (0a75b13) to head (c9b04de).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...template/put/PutComposableIndexTemplateAction.java 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #22421      +/-   ##
============================================
- Coverage     73.48%   73.42%   -0.07%     
+ Complexity    76464    76391      -73     
============================================
  Files          6101     6102       +1     
  Lines        346488   346525      +37     
  Branches      49871    49877       +6     
============================================
- Hits         254620   254432     -188     
- Misses        71599    71805     +206     
- Partials      20269    20288      +19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 94c1dc6

@github-actions

Copy link
Copy Markdown
Contributor

❌ Gradle check result for 94c1dc6: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit e273298

@github-actions

Copy link
Copy Markdown
Contributor

❌ Gradle check result for e273298: null

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit c579dbd

@github-actions

Copy link
Copy Markdown
Contributor

❌ Gradle check result for c579dbd: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

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

Labels

bug Something isn't working Cluster Manager

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[BUG] NPE when creating a match-all composable index template without an inline template block

1 participant