opensearch-project / opensearch-project/OpenSearch
[BUG] possible NPE in SnapshotsService.java
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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