Skip to content

CacheFilter,when value is null,it will throw NPE(if use ehcache for jcache),why not check null here #1597

Closed

Description

@celesky

com.alibaba.dubbo.cache.filter.CacheFilter
when value is null,it will throw NPE(if use ehcache for jcache),why not check null here?
if the value is null ,maybe we have no need to cache it.

`package com.alibaba.dubbo.cache.filter;
public class CacheFilter implements Filter {

private CacheFactory cacheFactory;

public void setCacheFactory(CacheFactory cacheFactory) {
    this.cacheFactory = cacheFactory;
}

public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
        Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            if (cache != null && key != null) {
                Object value = cache.get(key);
                if (value != null) {
                    return new RpcResult(value);
                }
                Result result = invoker.invoke(invocation);
                **if (!result.hasException()) {**// should check value null or not ?
                    cache.put(key, result.getValue());
                }
                return result;
            }
        }
    }
    return invoker.invoke(invocation);
}

}`

Activity

  1. added a commit that references this issue on May 22, 2018
  2. added this to the 2.6.3 milestone on Jul 23, 2018
  3. added a commit that references this issue on Sep 9, 2019
  4. added a commit that references this issue on Sep 10, 2019
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

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions