apache / apache/shenyu

[BUG] TarsPlugin throws on empty/uninitialized proxy list (nextInt(0))

Open Beginner friendly
#6,652 1 comment 0 reactions 0 assignees View on GitHub
plugin: tars priority: high type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- severity: High
- files: `shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/TarsPlugin.java:81-83`
- description: `ApplicationConfigCache.get(path)` is a Guava `LoadingCache` whose loader returns a `TarsInvokePrxList(null,null,null)` with an empty internal list when the path was never initialized. Line 82 `ThreadLocalRandom.current().nextInt(tarsInvokePrxList.getTarsInvokePrxList().size())` throws `IllegalArgumentException` when the list is empty, outside the try/catch.
- impact: Any request for a tars path whose proxy list is not yet populated (race during sync, or no upstreams) results in uncaught `IllegalArgumentException` → 500.
- suggested_fix: Guard `size() == 0` and return a proper no-upstream error via `WebFluxResultUtils.result(...)`.
- confidence: High
- related_existing: none — #6567 is about unbounded maps, not this NPE.

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/main/java/org/apache/shenyu/plugin/tars/TarsPlugin.java at lines 81-83, and inspect how WebFluxResultUtils.result(...) reports other upstream failures. Verify the empty proxy-list path no longer reaches nextInt(0), returns the proper no-upstream response, and preserves normal selection when proxies are available.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.