[BUG] Deleting an unknown discovery id throws NPE
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Current Behavior
Deleting a discovery record by an unknown id can throw `NullPointerException`.
`DiscoveryController.delete()` accepts any `discoveryId` path value and delegates directly to `discoveryService.delete(discoveryId)`. In the service, `discoveryMapper.selectById(discoveryId)` can return `null`, but the next line dereferences it:
```java
DiscoveryDO discoveryDO = discoveryMapper.selectById(discoveryId);
DiscoveryProcessor discoveryProcessor = discoveryProcessorHolder.chooseProcessor(discoveryDO.getDiscoveryType());
```
### Expected Behavior
Deleting an unknown discovery id should return a controlled not-found/parameter error response instead of an internal server error.
### Steps to Reproduce
```http
DELETE /discovery/not-exist
```
If no discovery row exists for that id, `discoveryDO.getDiscoveryType()` can throw.
### Code Location
- `shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/DiscoveryController.java`
- `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with DiscoveryController.java and DiscoveryServiceImpl.java, then reproduce DELETE /discovery/not-exist to observe the current response. Check nearby handling for missing records and existing tests before making the behavior consistent. Done means an unknown discovery id returns a controlled not-found or parameter error instead of a NullPointerException.
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