Netflix/Hystrix · error · HystrixCachingException

method with name '{}' doesn't exist in class '{}'

Error message

method with name '{}' doesn't exist in class '{}'

What it means

With @CacheRemove/@CacheResult caching, you can point to a cacheKeyMethod that computes the cache key. Javanica looks it up on the target class with getDeclaredMethod(clazz, method, <same parameter types as the annotated method>) and throws HystrixCachingException when nothing matches. Both the name and the exact parameter-type list must line up with the annotated method.

Source

Thrown at hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/cache/CacheInvocationContextFactory.java:74

     * @return initialized and configured {@link CacheInvocationContext}
     */
    public static CacheInvocationContext<CacheRemove> createCacheRemoveInvocationContext(MetaHolder metaHolder) {
        Method method = metaHolder.getMethod();
        if (method.isAnnotationPresent(CacheRemove.class)) {
            CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class);
            MethodExecutionAction cacheKeyMethod = createCacheKeyAction(cacheRemove.cacheKeyMethod(), metaHolder);
            return new CacheInvocationContext<CacheRemove>(cacheRemove, cacheKeyMethod, metaHolder.getObj(), method, metaHolder.getArgs());
        }
        return null;
    }

    private static MethodExecutionAction createCacheKeyAction(String method, MetaHolder metaHolder) {
        MethodExecutionAction cacheKeyAction = null;
        if (StringUtils.isNotBlank(method)) {
            Method cacheKeyMethod = getDeclaredMethod(metaHolder.getObj().getClass(), method,
                    metaHolder.getMethod().getParameterTypes());
            if (cacheKeyMethod == null) {
                throw new HystrixCachingException("method with name '" + method + "' doesn't exist in class '"
                        + metaHolder.getObj().getClass() + "'");
            }
            if (!cacheKeyMethod.getReturnType().equals(String.class)) {
                throw new HystrixCachingException("return type of cacheKey method must be String. Method: '" + method + "', Class: '"
                        + metaHolder.getObj().getClass() + "'");
            }

            MetaHolder cMetaHolder = MetaHolder.builder().obj(metaHolder.getObj()).method(cacheKeyMethod).args(metaHolder.getArgs()).build();
            cacheKeyAction = new MethodExecutionAction(cMetaHolder.getObj(), cacheKeyMethod, cMetaHolder.getArgs(), cMetaHolder);
        }
        return cacheKeyAction;
    }

}

View on GitHub (pinned to 5ce3bc58c3)

Solutions

  1. Declare a method with the exact name given in cacheKeyMethod that takes the same parameter types as the annotated method and returns String.
  2. Check spelling and case of cacheKeyMethod.
  3. If the key needs fewer inputs, keep the same parameter list anyway and ignore unneeded arguments, or build the key inline via @CacheKey on parameters instead.

Example fix

// before
@CacheRemove(commandKey = "getUser", cacheKeyMethod = "userKey")
public void updateUser(User u) { ... }
private String userKey(Long id) { ... }  // wrong params

// after
@CacheRemove(commandKey = "getUser", cacheKeyMethod = "userKey")
public void updateUser(User u) { ... }
private String userKey(User u) { return u.getId(); }
Defensive patterns

Strategy: validation

Validate before calling

static void assertCacheKeyMethodExists(Object target, Method annotated, String keyMethodName) {
    if (keyMethodName == null || keyMethodName.trim().isEmpty()) return;
    Method found = null;
    try { found = target.getClass().getDeclaredMethod(keyMethodName, annotated.getParameterTypes()); } catch (NoSuchMethodException ignored) { }
    if (found == null) throw new IllegalStateException("cacheKeyMethod '" + keyMethodName + "' with matching params not found on " + target.getClass());
}

Try / catch

try { ... } catch (HystrixCachingException e) { if (e.getMessage().contains("doesn't exist")) { fail fast with class+method names; } rethrow; } — config defect, never recoverable at runtime.

Prevention

When it happens

Trigger: @CacheRemove(cacheKeyMethod = "keyFor") where keyFor does not exist, is misspelled, is declared in a superclass (getDeclaredMethod only sees the class itself), or takes different parameter types than the annotated method (extra/missing params, int vs Integer).

Common situations: Renaming the key method; refactoring the annotated method's parameters without updating the key method's signature; key method overloaded so reflection picks nothing exact.

Related errors


AI-assisted analysis of Netflix/Hystrix@5ce3bc58c3 (2026-08-14). Data as JSON: /api/errors/127169af8f1266fa. Report an issue: GitHub.