Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ExpressionUtil always return false issue #682

Merged
merged 1 commit into from
Jul 12, 2022
Merged

Conversation

devefx
Copy link
Contributor

@devefx devefx commented Jul 11, 2022

当缓存方法无参数时,会一直load数据,结果测试发现此处判断有误,c.getArgs()永远都不会是null

    public Object invoke(final MethodInvocation invocation) throws Throwable {
        \\ invocation.getArguments() 如果无参数时,每次会返回新的new Object[0]数组,导致cache一直被load
        context.setArgs(invocation.getArguments()); 

当缓存方法无参数时,会一直load数据,结果测试发现此处判断有误,c.getArgs()永远都不会是null
```
    public Object invoke(final MethodInvocation invocation) throws Throwable {
        \\ invocation.getArguments() 如果无参数时,每次会返回新的new Object[0]数组,导致cache一直被load
        context.setArgs(invocation.getArguments()); 

```
@CLAassistant
Copy link

CLAassistant commented Jul 11, 2022

CLA assistant check
All committers have signed the CLA.

@areyouok areyouok merged commit 5bafca8 into alibaba:master Jul 12, 2022
areyouok pushed a commit that referenced this pull request Jul 12, 2022
当缓存方法无参数时,会一直load数据,结果测试发现此处判断有误,c.getArgs()永远都不会是null
```
    public Object invoke(final MethodInvocation invocation) throws Throwable {
        \\ invocation.getArguments() 如果无参数时,每次会返回新的new Object[0]数组,导致cache一直被load
        context.setArgs(invocation.getArguments()); 

```
@areyouok
Copy link
Collaborator

当缓存方法无参数时,会一直load数据,结果测试发现此处判断有误,c.getArgs()永远都不会是null

    public Object invoke(final MethodInvocation invocation) throws Throwable {
        \\ invocation.getArguments() 如果无参数时,每次会返回新的new Object[0]数组,导致cache一直被load
        context.setArgs(invocation.getArguments()); 

这个能重现吗?单元测试里面无参数方法是能cache住的。见
SpringTest.testTestBean()

Assert.assertEquals(bean.count(), bean.count());

@devefx
Copy link
Contributor Author

devefx commented Jul 12, 2022

image

CacheInvokeContext context = configProvider.getCacheContext().createCacheInvokeContext(cacheConfigMap);

图1:可以看到方法没有参数时MethodInterceptor的invoke方法中获取到的invocation.getArguments()为Object[0]而不是null
image

图2:此处将至invocation.getArguments()赋值给CacheInvokeContext的Args,可以看到context的hashCode为@26356
image

https://github.com/alibaba/jetcache/blob/master/jetcache-anno/src/main/java/com/alicp/jetcache/anno/method/ExpressionUtil.java#L65

图3:由前面的图可以判断此次args == null永远都返回false,因为args不可能为null(此PR我已经在本地应用)

主要原因还是无参方法AOP的invocation.getArguments()将返回Object[0]而不是null导致的

版本号:

aopalliance 版本号:1.0
springboot 版本号:2.1.6 RELEASE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants