Skip to content

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

Description

@wangwang0555

Search before asking

  • I have searched the existing 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<ProductDTO> 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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞Something isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions