opensearch-project / opensearch-project/OpenSearch

[BUG] possible NPE in SnapshotsService.java

Open
#17,841 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Storage:Snapshots
Dominant language
Java
Stars
13.7k
Forks
3k
Avg merge
2d 23h
Merged PRs (30d)
108

Description

Describe the bug

Hello.

We've analyzed Opensearch sources with SAST and it pointed out possible NPE in https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/snapshots/SnapshotsService.java#L3410

                final IndexRoutingTable indexRoutingTable = routingTable.index(indexName);
                for (int i = 0; i < indexMetadata.getNumberOfShards(); i++) {
                    final ShardId shardId = indexRoutingTable.shard(i).shardId();
                    final String shardRepoGeneration;

                    final String inFlightGeneration = inFlightShardStates.generationForShard(index, shardId.id(), shardGenerations);
                    if (inFlightGeneration == null && isNewIndex) {
                        assert shardGenerations.getShardGen(index, shardId.getId()) == null : "Found shard generation for new index ["
                            + index
                            + "]";
                        shardRepoGeneration = ShardGenerations.NEW_SHARD_GEN;
                    } else {
                        shardRepoGeneration = inFlightGeneration;
                    }
                    final ShardSnapshotStatus shardSnapshotStatus;
                    if (indexRoutingTable == null) {
                        shardSnapshotStatus = new ShardSnapshotStatus(

If indexRoutingTable is null, then shards processing will throw NPE.
I didn't get this peace of code, so even can't propose PR, it'll be nice if someone more experienced will take a look

Related component

No response

To Reproduce

Didn't catch it in action, just static analysis of the code

Expected behavior

No NPE if indexRoutingTable is null

Additional Details

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read server/src/main/java/org/opensearch/snapshots/SnapshotsService.java around line 3410 and trace how indexRoutingTable is obtained before shard processing. Confirm whether the reported null state is reachable, then locate or add a focused snapshot-service regression test; the work is done when that state no longer causes an NPE.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.