arextest / arextest/arex-agent-java

[Bug] 使用@Cacheable缓存外部接口结果,当配置了缓存为空继续执行请求接口,回放请求报NullPointerException

Open
#614 1 comment 0 reactions 0 assignees View on GitHub
bug :lady_beetle:
Dominant language
Java
Stars
564
Forks
140
Avg merge
36m
Merged PRs (30d)
2

Description

### Search before asking

- [x] I have searched the existing [issues](https://github.com/arextest/arex-agent-java/issues) before asking.

### AREX Test Service

AREX Java Agent (arextest/arex-agent-java)

### Current Behavior

当使用@Cacheable缓存外部接口的结果,配置unless = "#result == null" 缓存不存在继续执行外部请求时,回放该请求会报NPE
**示例代码如下:**

`@Cacheable(value = "TEST", key = "#id", unless = "#result == null") `

`@Override public ProductDTO getProduct(final Integer id) { `

`final DataResponse dataResponse = client.getProductById(id); `

`return dataResponse.getData(); `

`}`

**Mock的数据如下:**

- 只有getProduct(final Integer id) 这个方法的mock,client.getProductById(id)并没有看到mock信息

Image

**报错信息:**
`java.lang.NullPointerException: `

`null at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:158) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:78) at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103) at `

`com.sun.proxy.$Proxy239.getProductById(Unknown Source)`

**本地debug后初步分析:**

- 在回放流量的时候,会继续执行client.getProductById方法但是因为该方法并没有mock数据导致报了NPE

### Expected Behavior

执行client.getProductById不要报NPE

### Steps To Reproduce

**组件版本**

- spring-cloud-starter-openfeign 2.1.0
- httpclient 4.5.12

### Anything else

### Are you willing to submit a pull request to fix on your own?

- [ ] Yes I am willing to submit a pull request on my own!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the replay path for a @Cacheable method using unless = "#result == null" and trace the call to client.getProductById(id), which lacks mock data in the report. Reproduce with spring-cloud-starter-openfeign 2.1.0 and httpclient 4.5.12; done means replaying this case does not raise the reported NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.